Pick the fix
Java code must call Prices.format(1.5) as a static method. What do you add?
class Prices {
companion object {
fun format(value: Double): String = "€%.2f".format(value)
}
}Hint 1 of 1
How does Java see companion functions by default?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A @JvmStatic on the function inside the companion object
Correct. Without it, Java has to call Prices.Companion.format.
Why not the others?
- B
@JvmField. That's for properties, not functions. - C
@JvmOverloads. That generates overloads for default arguments. - D
const. const applies to properties with constant values.