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

arkadiy

06/13/2017, 10:16 AM
Hello guys, given Java interface
interface Foo { int bar(); }
why do I need an explicit labeled return in Kotlin when using SAM conversion when creating a property - instance of this interface:
val foo = Foo { return@Foo 5}
why cannot I just write:
val foo = Foo { return 5 }
I know that I can just write it as
val foo = Foo { 5 }
, but I wonder why I need the labeled return in the second example
r

radityagumay

06/13/2017, 5:39 PM
arkadiy: This is a statement not expression.
arkadiy: that's why, they need to @ to return a value, you can omit it
a

arkadiy

06/14/2017, 6:44 AM
@radityagumay Could you elaborate more, please?
3 Views