PurelyImplements
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 { ... }
Content copied to clipboard
Methods defined in MyList
use T
as platform, i.e. it's possible to perform unsafe operation in Kotlin:
MyList().add(null) // compiles
Content copied to clipboard
@PurelyImplements("kotlin.collections.MutableList")
class MyPureList extends AbstractList { ... }
Content copied to clipboard
Methods defined in MyPureList
overriding methods in MutableList
use T
as non-platform types:
MyPureList().add(null) // Error
MyPureList().add(null) // Ok
Content copied to clipboard