codeslubber
03/16/2017, 5:09 PMdathoang.se
03/16/2017, 5:09 PMcodeslubber
03/16/2017, 5:09 PMcodeslubber
03/16/2017, 5:10 PMdathoang.se
03/16/2017, 5:11 PMbenleggiero
03/16/2017, 5:33 PMredrield
03/16/2017, 6:55 PMredrield
03/16/2017, 6:55 PMra1nmak3r
03/16/2017, 7:06 PMcedric
03/16/2017, 7:06 PMto
gets picked from the receiver firstcedric
03/16/2017, 7:07 PMPasted image at 2017-03-16, 12:07 PM▾
redrield
03/16/2017, 7:09 PMredrield
03/16/2017, 7:09 PMredrield
03/16/2017, 7:10 PMcedric
03/16/2017, 7:14 PMinterface II {
}
override fun configure() {
bind(II::class.java).to(object : II {})
}
redrield
03/16/2017, 7:15 PMredrield
03/16/2017, 7:15 PMnimtiazm
03/16/2017, 7:22 PMmikehearn
03/16/2017, 7:31 PMmikehearn
03/16/2017, 7:32 PMredrield
03/16/2017, 7:47 PMcedric
03/16/2017, 7:50 PM.class
or .class.java
?redrield
03/16/2017, 7:51 PMredrield
03/16/2017, 7:51 PMcedric
03/16/2017, 7:52 PM.class
, which would explain why IDEA didn’t resolve Guice’s to
and jumped to `Pair`‘s insteadarild
03/16/2017, 7:59 PMclass SomeClass {
val myEventListener = { log(”got event ${it) }
fun onEventProducerAttached(producer: EventProducer) {
log(”hashcode before passing listener: ${myEventListener.hashCode()}“)
producer.addEventListener(myEventListener)
}
fun onEventProducerDetached(producer: EventProducer) {
producer.removeEventListener(myEventListener)
}
…
class EventProducer {
...
addEventListener(listener: () -> Unit) {
log(”hashcode when receiving passed listener: ${myEventListener.hashCode()}“)
...
}
}
the addEventListener receives a different instance in addEventListener
and removeEventListener
.
More explicitly: the haschode recorded in the log from the passing code and the receiving code will be different.
Unless I am mistaken about this behaviour, I think this should be made very clear in the Kotlin reference to avoid people stumbling over it (as I have done for the last hour).
Also, if there already exists documentation to read up on the implementation of lambdas and method references and why the behaviour I describe above is as it is, I would be very grateful if someone could point me towards it.michaelsims
03/16/2017, 8:12 PMarild
03/16/2017, 8:15 PMmichaelsims
03/16/2017, 8:16 PMarild
03/16/2017, 8:16 PM