Hi, I was wondering if there was any reason Kotlin...
# announcements
l
Hi, I was wondering if there was any reason Kotlin/JVM seems not to use LambdaMetaFactory when creating lambda objects by default, instead opting to make a new class for every single lambda? Also, is there any way I can tell it to use LMF? Thanks
l
Ahh it's opt-in at the moment
thanks so much
d
Yes and the reasons are explained there as well
l
Great, thank you!
s
A lambda compiled into invokedynamic is not serializable
So normally, you can serialize lamdas and store in database?
d
Yes,
kotlin.jvm.internal.Lambda
(the base class for lambdas generated by the compiler on the JVM) implements
java.io.Serializable
, so it can be serialized using the Java serialization mechanism - provided any captured variables are also serializable.
You probably should never do that though!
e
serializing lambdas is questionable, but serializable method references (e.g.
String::isEmpty
) could be considered reasonable
(Java 8 doesn't support serializing either, but as the linked YouTrack issue mentions, changing Kotlin's behavior is a compatibility break, although hopefully one that doesn't affect many users)
d
Java 8 definitely has serializable lambdas. Brian Goetz and colleagues lost many a hair over that if their talks are to trust 🙂