towe
May 1, 2012, 12:06pm
1
Hello,
I’m experimenting with Kotlin, Wicket and Guice.
I have a trait implemented by a class (class MyServiceImpl : MyService). I tried to wire this up in my guice module by:
class MyModule : AbstractModule() {
protected override fun configure() {
bind(javaClass<MyService>).to (javaClass<MyServiceImpl>).in (Scopes.SINGLETON);
}
}
This causes multiple problems:
the “to” gets confused with the global “kotlin.to” function, would “import kotlin.to as kotlinTo” solve this?
the method “in” conflicts with the in-operator in Kotlin, how can I call a java-objects with methods named “in”?
/Tobias W
1. The 'to' problem seems to be a bug: Binder.to() is a member, so the to() extension function should not interfere. Please, file an issue about it.
2. To work around the 'in' problem, use backtics around it: `in`
towe
May 1, 2012, 12:46pm
3
towe
May 3, 2012, 2:59pm
4
Just as a reference for the future:
Turns out that this wasn’t a bug at all but me being a noob. See Svetlana’s comment: http://youtrack.jetbrains.com/issue/KT-1874#comment=27-327499 .
If I understand it correctly the kotlin to-extension-method was resolved because the return value of the “bind” method is nullable.
The correct code should be using ‘!!’, ‘?’ or ‘.sure()’:
class MyModule : AbstractModule() {
protected override fun configure() {
bind(javaClass<MyService>)!! .to (javaClass<MyServiceImpl>)!! .in (Scopes.SINGLETON);
}
}
/Tobias W