r/java • • 4d ago

Primitive classes in javac

https://github.com/openjdk/valhalla/pull/2691/changes

Javac is being taught about primitive classes as a preview feature. While marked as added in Java 28, I'm guessing we won't have a way to use it considering that there's no JEP even.

From reading the code:

  • primitive classes are implicitly value classes (JEP 401) (immutable, can be abstract and then optionally sealed...).
  • Implicitly static when nested like record.
  • Uniquely, the class name starts (or should start) with a lowercase, like primitive types.
  • Interfaces and enums cannot be primitive.
  • Can be generic and can implement interfaces like anything else*.
  • Unsurprisingly, all the examples are for numeric types (like complex numbers and points).

I assume that they are non-null by default because they are not reference types. I would be cautious about extrapolating from the older Valhalla models that talked about primitive classes, they might not be the same "primitive class".

*except for generic enums :(

63 Upvotes

69 comments sorted by

View all comments

Show parent comment

3

u/brian_goetz 4d ago

"Barely in" is a wild exaggeration. More like "barely on the edge of the map of things that might some day be candidates."