curric

View on GitHub

./curric/kotlin/oop/jvm-annotations/

\@JVM Annotations

The following are Jvm specific annotations to help with Java interoperability

Note that if an interface with @JvmDefault methods is used as a delegate, the default method implementations are called even if the actual delegate type provides its own implementations. ```kotlin interface Producer { @JvmDefault fun produce() { println(“interface method”) } }

class ProducerImpl: Producer { override fun produce() { println(“class method”) } }

class DelegatedProducer(val p: Producer): Producer by p {}

fun main() { val prod = ProducerImpl() DelegatedProducer(prod).produce() // prints “interface method” } ```