用Kotlin创建自定义匕首2范围
我试图将Java代码转换为Kotlin来创建自定义匕首范围。
这里是Java代码:
@Documented @Scope @Retention(RetentionPolicy.RUNTIME) public @interface CustomScope { }
一旦转换成kotlin这是结果
@Scope @Documented @Retention(RetentionPolicy.RUNTIME) annotation class CustomScope
我有一个与@Retention(RetentionPolicy.RUNTIME)
types不匹配。我有以下错误信息:必需types是AnnotationRetention,但findRetentionPolicytypes。
@interface似乎已被替换。
您可能使用的Retention
注释类是从Kotlin的库(来自包kotlin.annotation
)。
它期望枚举typesAnnotationRetention
一个属性。 所以,你可以做这样的事情:
@MustBeDocumented @Scope @Retention(AnnotationRetention.RUNTIME) annotation class CustomScope
顺便说一句,如果你看Annotations.kt
文件,你会看到,当你没有传递任何东西的时候, Retention
注解将会使用默认的AnnotationRetention.RUNTIME
属性。
所以,只需@Retention
注解也可以。
- 如何将此代码从iOS Swift转换为Android Kotlin
- (Java + Kotlin)自动assembly(Autowiring):预计至少有1个bean可以作为这个依赖关系的autowire候选者
- Kotlin:通过Kotlin中的Data类在Java类中设置一个私有布尔值。 为什么我无法做到这一点?
- 如何在kotlin中实现finalize()?
- 当处于调试器模式时,Android Studio 1.5与Kotlin Pluginexception。 如何解决它?
- Kotlin为Android和静态最终的内部类
- Java 8 stream.collect(Collectors.toMap())类似于kotlin
- 在java类中调用扩展函数作为任何RX操作符
- Realm&Kotlin访问字段的变量