Create Custom Dagger 2 Scope with Kotlin

前端 未结 1 661
挽巷
挽巷 2021-01-11 17:14

I\'m trying to convert a Java code into Kotlin for custom dagger scope creation.

Here is Java code:

@Documented
@Scope
@Retention(RetentionPolicy.RUN         


        
1条回答
  •  天涯浪人
    2021-01-11 17:38

    The Retention annotation class which you might have used is from the Kotlin's library (from the package kotlin.annotation).

    It expects a property of the enum type AnnotationRetention. So, you can do something like this:

    @MustBeDocumented
    @Scope
    @Retention(AnnotationRetention.RUNTIME)
    annotation class CustomScope
    

    Btw, if you look at the Annotations.kt file, you will see that that the Retention annotation will take the default property AnnotationRetention.RUNTIME when you don't pass anything to it.

    So, just @Retention annotation will do too.

    0 讨论(0)
提交回复
热议问题