Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Looking into Java's Future: Empty Value Types

DZone's Guide to

Looking into Java's Future: Empty Value Types

Have you ever wondered about using Java's value types? Read more here about what Java programmers have to say about the empty value type.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Although the promising Java value types are not imminent, I still enjoy nosing around occasionally in the OpenJDK Valhalla-dev mailing list to see how things are progressing and to get an idea of what is to come. Admittedly, there are some discussions that are beyond my understanding, given my limited exposure to the terms used and the low-level specifics of some messages. However, occasionally, there are messages and threads that I understand and find interesting. A recent example of this is the "Empty value type ?" thread.

Rémi Forax starts the thread by asking "Is empty value type targeted for LW1?" The example error message included with that question shows as a LinkageError and a ClassFormatError with the message "Value Types do not support zero instance size yet." The response to this question from Tobias Hartmann says, "No, empty value types are not planned to be supported for LW1."

Before moving onto the rest of the thread (which is the part that interested me the most), I'll quickly discuss "LW1." In a message on that same OpenJDK mailing list called "[lworld] LW1 - 'Minimal LWorld'," David Simms states, "we are approaching something 'usable' in terms of 'minimal L World' (LW1)" and "we will be moving of prototyping to milestone stabilization." That same message states that the "label" is "lw1." Along with that, the affected-version and fixed-version are both "repo-valhalla". In other words, "LW1" is the label used to track bugs and issues related to work on the "minimal L world" implementation. You can reference John Rose's 19 November 2017 message, "abandon all U-types, welcome to L-world (or, what I learned in Burlington)" for an introduction to the "L World" term and what it means in terms of value types.

Returning to the "Empty value type?" thread, Kirk Pepperdine asked a question that also occurred to me, "How can a value type be empty?" He added, "What is an empty integer? An empty string?" He said he was "just curious" and now I am too. Here is a summary of the informative responses:

  • Rémi Forax: "type [that] represents the absence of value like unit, void, or bottom"
  • Rémi Forax: "type that represents the result of a throw"
  • Rémi Forax: "type that allows HashSet<E> to be defined as HashMap<E,Empty>"
    • Brian Goetz's message elaborates on the value of this, "Zero-length values can be quite useful, just not directly. Look at the current implementations of Set that delegate to HashMap; all that wasted space. When we have specialized generics, they can specialize to HashMap<T, empty>, and that space gets squeezed away to zero."
  • Rémi Forax: "transformative type like a marker type that separate arguments" (see the message for example of this one)

I also liked the final (as of this writing) Kirk Pepperdine message on that thread where he summarizes, "Feels like a value type version of null."

Incidentally, there are some other interesting messages and threads in the June 2018 Archives of the Valhalla-dev mailing list. Here are some of them:

I look forward to one day being able to apply value types in my everyday Java code. Until then, it is interesting to think about and also to see how much work is going into making these value types.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:
java ,value types ,hashmap ,lw1 ,openjdk

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}