/
PurelyImplements.kt
39 lines (37 loc) · 1.14 KB
/
PurelyImplements.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package kotlin.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:
*
* ```java
* 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:
*
* ```kotlin
* MyList<Int>().add(null) // compiles
* ```
*
* ```java
* @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:
*
* ```kotlin
* MyPureList<Int>().add(null) // Error
* MyPureList<Int?>().add(null) // Ok
* ```
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
public annotation class PurelyImplements(val value: String)