Recall & Review
beginner
What does the
@JvmStatic annotation do in Kotlin?It makes a Kotlin function or property appear as a static method or field in Java, allowing Java code to call it without needing an instance.
Click to reveal answer
beginner
How does
@JvmField affect Kotlin properties when accessed from Java?It exposes the Kotlin property as a public Java field, removing the getter/setter methods and allowing direct field access from Java.
Click to reveal answer
intermediate
When should you use
@JvmStatic in Kotlin companion objects?Use <code>@JvmStatic</code> on functions or properties inside companion objects to let Java callers access them as static members of the containing class.Click to reveal answer
intermediate
What is the difference between a Kotlin property with
@JvmField and a regular Kotlin property without it when accessed from Java?With
@JvmField, Java code accesses the property as a field directly. Without it, Java accesses it via getter/setter methods.Click to reveal answer
advanced
Can
@JvmStatic be used on top-level Kotlin functions?No,
@JvmStatic is only applicable inside companion objects or named objects. Top-level functions are already static in Java bytecode.Click to reveal answer
What does
@JvmStatic do when applied to a function inside a Kotlin companion object?✗ Incorrect
@JvmStatic allows Java code to call the function as a static method on the containing class.
Which annotation exposes a Kotlin property as a public field in Java, skipping getter/setter methods?
✗ Incorrect
@JvmField exposes the property as a public field in Java.
Can
@JvmStatic be used on top-level Kotlin functions to make them static in Java?✗ Incorrect
Top-level functions are already static in Java bytecode, so @JvmStatic is not needed and only works inside companion or named objects.
What happens if you do NOT use
@JvmField on a Kotlin property accessed from Java?✗ Incorrect
Without @JvmField, Java uses getter/setter methods to access Kotlin properties.
Which Kotlin annotation helps Java callers access companion object members as static members of the class?
✗ Incorrect
@JvmStatic makes companion object members appear as static members in Java.
Explain how
@JvmStatic and @JvmField improve Kotlin and Java interoperability.Think about how Java expects static methods and fields.
You got /4 concepts.
Describe when and why you would use
@JvmStatic inside a Kotlin companion object.Consider Java's static method calling style.
You got /4 concepts.