2 ms·
It looks like this is going to be the Java version of Kotlin's lazy [0] and Scala's lazy val [1]. [0] https://kotlinlang.org/docs/delegated-properties.html#laz
by lolinder 3y ago
It looks like this is going to be the Java version of Kotlin's lazy [0] and Scala's lazy val [1].
[0] https://kotlinlang.org/docs/delegated-properties.html#lazy-properties https://kotlinlang.org/docs/delegated-properties.html#lazy-p...
[1] https://www.baeldung.com/scala/lazy-val https://www.baeldung.com/scala/lazy-val
- mfiguiere 3y agoThere were another JEP draft [1] recently that was proposing to introduce a lazy keyword for static fields. This new JEP looks like an alternative without any language change, and seems more likely to prevail. [1] JEP draft: Lazy Static Final Fields - https://openjdk.org/jeps/8209964 https://openjdk.org/jeps/8209964
- paulirwin 3y agoIt also seems very similar to .NET's Lazy<T>: https://learn.microsoft.com/en-us/dotnet/api/system.lazy-1?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.lazy-1?v...
- pron 3y agoNot quite. You need to have control over the JVM to do what this class does. The whole point of this class is a lazy value that interacts with the JIT in desirable ways.
- lolinder 3y agoSure, but that's an (important) implementation detail. If this JEP is merged both Scala and Kotlin could implement their respective features in terms of ComputedConstant and get the performance enhancements for free. Meaning it's semantically the same, with non-functional benefits.