Java: New Draft JEP: “Computed Constants”
minborgsjavapot.blogspot.com
minborgsjavapot.blogspot.com
The point is that static final variables interact especially well with the JIT's constant folding machinery. But lazy loading a constant necessitates that it can't be final: it's initially null until it's effectively final after the first lazy load. This finality is clear to the developer but not to the JVM.
This is introduces a way to implement lazy constants via a blessed class that solves this.
The article is pretty clear about what the point is — but does require some careful reading and context.
https://github.com/spullara/java-future-jdk8/blob/master/src...
https://openjdk.org/projects/leyden/notes/02-shift-and-const...
But for the love of Glob I wish web page authors would cease their contrast brinkmanship. Most of the text is barely discernible from the background.
[1] https://en.wikipedia.org/wiki/Initialization-on-demand_holde...
[0] https://kotlinlang.org/docs/delegated-properties.html#lazy-p...
[1] JEP draft: Lazy Static Final Fields - https://openjdk.org/jeps/8209964
Meaning it's semantically the same, with non-functional benefits.
private static final Log log = const Log.getLog("yo");
instead of all that rigmarole around ComputedConstants?A commenter above points out that there's a competing proposal that does introduce new syntax in the form of a `lazy` keyword:
$$('div, h1, h2').forEach(e => e.style.color = '#111')In all seriousness, this is grade school BS.
(a) Literals are a syntax improvement. Much more serious languages than Java have them.
(b) What Python and JS have don't amount to "simple lists and maps". They have the full gamut (including constructor based instantiation of different types).
(c) Literals don't have to be a single ("simple" or not) type. They can be whatever, and in Java these could include different classes of lists and maps initialized with the same literal syntax based on the assigned variable's type.
(d) When Oracle gives literals, Java programmers not familiar with them in other languages will suddenly love them too, and they'd not just be "for Python and Javascript" anymore.
mapOf("a" to 1, "b" to 2)
...where "to" is actually an infix extension function that creates a Pair object, so there is no special syntax for maps.Any class doing IO is a dependency, so you normally would just inject it via the constructor of the class.