Is there a way to specify that I want to use boxed...
# announcements
d
Is there a way to specify that I want to use boxed version of
val
? I use DI framework and it finds primitive
boolean
here:
Copy code
class MyPresenter @Inject constructor(val field: Boolean)
and fails to generate injector. One way is to use
val field: java.lang.Boolean
, but it feels a bit dirty and generates a warning
h
Wouldn't
val field: Boolean?
work?
k
import java.lang.Boolean as BBoolean
and then use that.
👍 1
d
Should Boolean really be used as an injectable? I think you should just wrap that
a
If you use spring DI you can use
Copy code
@Configuration
class AppConfig(
@Value("\${my-app.boolean}") private val bool: Boolean)
Or you can use nullable var
Copy code
@Configuration
class AppConfif() {
  @Value("\${my-app.boolean}") 
  var: Boolean? = null
}
Maybe in your case you could use nullable Boolean?
Copy code
class MyPresenter @Inject constructor(val field: Boolean?)
Anyway it should be supported by DI framework. If framework doesn't support constructor injection it may be problem in kotlin with primitives, because in Kotlin all primitives is not null unlike Java
d
Thanks all!