toothpick
toothpick copied to clipboard
Boolean kotlin injection
So I spend some time today trying to inject boolean field.
I have
class A @Inject constructor(@Named("name") val booleanValue: Boolean)
I created module:
internal class BooleanModule(booleanValue: Boolean) : Module() {
init {
bind(Boolean::class.java).withName("name").toInstance(booleanValue)
}
Iteration 1:
- Code generation fails since
Booleantransformed to primitive by kotlin compiler and Toothpick don't have such functionality
Iteration 2:
- I forced kotlin to keep Boolean class
class A @Inject constructor(@Named("name") val booleanValue: Boolean?)This compiles but fails in the runtime since it can not find the providerNo binding was defined for class java.lang.Boolean and name
Iteration 3:
- I changed it to Any in the class and just cast it in runtime.
Am I doing something wrong and there is the simple solution?
I decided to go with the additional class InjectableBoolean that is just wrapper around boolean.