PurelyImplements.<init>
所在位置是kotlin.jvm.PurelyImplements.<init>
,其相關用法介紹如下。
用法:
指示 Kotlin 編譯器將帶注釋的 Java 類視為給定 Kotlin 接口的純實現。 "Pure" 在這裏表示類的每個類型參數都成為該接口的非平台類型參數。
例子:
class MyList<T> extends AbstractList<T> { ... }
MyList<T>
中定義的方法使用 T
作為平台,即在 Kotlin 中可能執行不安全的操作:
MyList<Int>().add(null) // compiles
@PurelyImplements("kotlin.collections.MutableList")
class MyPureList<T> extends AbstractList<T> { ... }
MyPureList<T>
中定義的方法覆蓋 MutableList
中的方法使用 T
作為非平台類型:
MyPureList<Int>().add(null) // Error
MyPureList<Int?>().add(null) // Ok
相關用法
- Kotlin PurelyImplements用法及代碼示例
- Kotlin Path.getAttribute用法及代碼示例
- Kotlin Pair用法及代碼示例
- Kotlin Path.setAttribute用法及代碼示例
- Kotlin Path.readAttributes用法及代碼示例
- Kotlin Path.copyTo用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin map用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin reduceRight用法及代碼示例
- Kotlin Random.Default用法及代碼示例
- Kotlin Byte.inc用法及代碼示例
- Kotlin getValue用法及代碼示例
- Kotlin Double.dec用法及代碼示例
- Kotlin windowedSequence用法及代碼示例
- Kotlin contentToString用法及代碼示例
- Kotlin groupByTo用法及代碼示例
- Kotlin commonPrefixWith用法及代碼示例
- Kotlin MatchResult.Destructured用法及代碼示例
- Kotlin Delegates.notNull用法及代碼示例
- Kotlin ifBlank用法及代碼示例
- Kotlin filterNotTo用法及代碼示例
- Kotlin getOrPut用法及代碼示例
- Kotlin Triple.<init>用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.jvm.PurelyImplements.<init>。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。