PurelyImplements

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class PurelyImplements(val value: String)(source)

Instructs the Kotlin compiler to treat annotated Java class as pure implementation of given Kotlin interface. "Pure" means here that each type parameter of class becomes non-platform type argument of that interface.

Example:

class MyList extends AbstractList { ... }

Methods defined in MyList use T as platform, i.e. it's possible to perform unsafe operation in Kotlin:

MyList().add(null) // compiles
@PurelyImplements("kotlin.collections.MutableList")
class MyPureList extends AbstractList { ... }

Methods defined in MyPureList overriding methods in MutableList use T as non-platform types:

MyPureList().add(null) // Error
MyPureList().add(null) // Ok

Since Kotlin

1.0

Properties

Link copied to clipboard
Since Kotlin 1.0