https://kotlinlang.org logo
#announcements
Title
# announcements
n

nitrog42

06/09/2017, 1:22 PM
hi guys ! interface SAMListener { public void listen(param1: Object, param2: Object) } myclass.setSAMListener { param1, (param2 as Boolean) -> } I’m trying to make param2 autocast to Boolean, but it’s not working... Is there any way to do it in the prototype of the lambda ?
m

mbickel

06/09/2017, 1:35 PM
nitrog42: Does this really have to be in the method signature? Why not cast it in the body?
n

nitrog42

06/09/2017, 1:36 PM
well i like the easy way 🙂
I mean cast is ok but require one more line, and param2 will always be a Boolean
m

mg6maciej

06/09/2017, 2:15 PM
It doesn't require one more line.
Copy code
myclass.setSAMListener {
  param1, param2 -> param2 as Boolean; !param2
}
n

nitrog42

06/09/2017, 2:20 PM
yes but it’s not as fluent, I need to reuse param2, instead of driectly saying “i have param1 and param2 which is a boolean”
it’s not possible, but I hope in the future we can do things like that
m

mg6maciej

06/09/2017, 2:25 PM
Well... I hope not. 🙂
👍 1
There is no point in intruducing complexity to language for such rare usecases.
2 Views