Reputation: 3192
Is there way to create a factory binding, which can produce null?
For example,
bind<String?> with factory { x: Int ->
when (x) {
1 -> "A"
2 -> "B"
else -> null
}
}
Unfortunately, bind<String?>
gives error.
Upvotes: 1
Views: 486
Reputation: 3192
End up with Optional
:
bind<Optional<String>> with factory { x: Int ->
when (x) {
1 -> Optional.of<String>("A")
2 -> Optional.of<String>("B")
else -> Optional.empty()
}
}
Upvotes: 3