作者:何博弘朗 | 来源:互联网 | 2023-01-03 11:49
我正在尝试将Java代码转换为Kotlin以创建自定义匕首.
这是Java代码:
@Documented
@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomScope {
}
一旦转换成kotlin,结果就是这里
@Scope
@Documented
@Retention(RetentionPolicy.RUNTIME) annotation class CustomScope
我有一个类型不匹配@Retention(RetentionPolicy.RUNTIME)
.我有以下错误消息:必需类型是AnnotationRetention但找到了RetentionPolicy类型.
@interface似乎也被取代了.
1> jayeshsolank..:
Retention
您可能使用的注释类来自Kotlin的库(来自包kotlin.annotation
).
它期望枚举类型的属性AnnotationRetention
.所以,你可以这样做:
@MustBeDocumented
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class CustomScope
顺便说一下,如果你看一下这个Annotations.kt
文件,你就会发现当你没有传递任何东西时,Retention
注释会采用默认属性AnnotationRetention.RUNTIME
.
所以,只需@Retention
注释也可以.