Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean kotlin injection #423

Open
emartynov opened this issue Jan 14, 2021 · 1 comment
Open

Boolean kotlin injection #423

emartynov opened this issue Jan 14, 2021 · 1 comment

Comments

@emartynov
Copy link

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 Boolean transformed 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 provider No 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?

@emartynov
Copy link
Author

I decided to go with the additional class InjectableBoolean that is just wrapper around boolean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant