Kotlin and Dagger: Can I use @Inject to an object still make it nullable/optional?

后端 未结 2 1454
心在旅途
心在旅途 2020-12-30 05:52

I need something that can make my class nullable/optional because of the runtime errors that is happening on some devices.

Is this possible?

class M         


        
相关标签:
2条回答
  • 2020-12-30 06:40

    I had the same problem and solved like this:

    @Inject
    @JvmField
    var presenter: Presenter? = null
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-30 06:48

    If you don't have Java code that needs to access the presenter field you don't need to annotate it with @JvmField. Instead, you can declare your field like so:

    @set:Inject
    var presenter: Presenter? = null
    
    0 讨论(0)
提交回复
热议问题