在Kotlin中将应用程序范围创建为单例

问题描述 投票:0回答:1

在使用Dagger2时在java中,我创建了application scope并按如下方式用作singleton

@Scope
@Retention(RetentionPolicy.CLASS)
public @interface MyApplicationScope {
}

问题: Now how to write the similar code in Kotlin

我尝试了什么

@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ApplicationScope

我没有获得选项.CLASS

enter image description here

android kotlin dagger-2
1个回答
0
投票
与Java的RetentionPolicy.CLASS等效的Kotlin为RetentionPolicy.CLASS。两者都引用需要保留在JAR或其他编译器输出文件中的注释,但不需要在运行时可用。
© www.soinside.com 2019 - 2024. All rights reserved.