In a android, kotlin project, seeing this @set:Inject
but could not find a good explanation. Anyone knows?
object Controller {
@set:Inject
lateinit var someData: SomeData
The @Inject
annotation can be used for method, constructor, or field:
@Target(value={METHOD,CONSTRUCTOR,FIELD})
It is important to remember that Java code will be generated from this Kotlin code and for one statement in Kotlin you can have multiple Java elements and that is why @set:Inject
explicitly specifies that the @Inject
annotation should be applied to the setter that will be generated in Java.
What happens if there is no use-site target defined? Official documentation provides a good explanation:
If you don't specify a use-site target, the target is chosen according to the @Target annotation of the annotation being used. If there are multiple applicable targets, the first applicable target from the following list is used:
- param (constructor parameter);
- property (annotations with this target are not visible to Java);
- field;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With