kotlin.jvm.PurelyImplements.<init>

<init>

PurelyImplements(value: String)

Platform and version requirements: JVM

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<T> extends AbstractList<T> { ... }

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

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

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

MyList<Int>().add(null) // Error
MyList<Int?>().add(null) // Ok

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-purely-implements/-init-.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部