What's the equality of lambdas? After reading the ...
# compiler
i
What's the equality of lambdas? After reading the languags specification, I found nothing about it.
3
😥 2
e
callable references have equality; otherwise unspecified
e
why must it be specified? Java doesn't specify for its lambdas either
i
@ephemient The official document give examples to use lambda as event handler. But in many case, the event handler need a specified equality definition.
e
it allows the possibility of optimizing instance creation of non-capturing lambdas
i
I got it. Be honest I haven't noticed it before found the optimization.
Maybe let it be an undefined behaviour is more suitable than unspecified.
If just for optimization, could we use annotation to hint the compiler that the lambda doesn't care equality?
Thinking about it again, I think the reason might be Kotlin want to following Java lambda implementation in the future. But Java is unspecified now, so Kotlin also leave it unspecified.
e
Kotlin is already using Java's LambdaMetaFactory in various cases