Suppose I have a list of lambdas like: `List<(I...
# getting-started
m
Suppose I have a list of lambdas like:
List<(Int) -> Unit>
but I’d rather be more explicit so define an
interface MyFun: (Int) -> Unit
so that my list now looks like
List<MyFun>
. However, now, to create such a
MyFun
, I need to do something like
object: MyFun { override invoke(val: Int) { //some stuff } }
. Does this mean I’m creating an extra object compared to with not using the interface? If so, is there a better way?
r
You can use
typealias MyFun = (Int) -> Unit
👍 6
m
Yep, I just tried that, thanks!
👍 1
d
Just to answer your original question: No, lambdas are also just objects, internally implementing an interface, at least on the JVM.
👍 2
a
Also doesn't the new type inference enable kotlin SAM conversion?
r
No, but there will be a new
fun interface
construct.