What does the primitive class work in javac mean for Java?

November 20, 2026 4 answers
Asked by c.584~drivmexa

I saw a javac change that treats primitive classes as a preview feature. How do they relate to value classes, and does the Java 28 marker mean we can expect to use them then?

Answers

_h52+velnori.7

The compiler change appears to make primitive classes implicitly value classes. It also treats nested primitive classes as implicitly static, permits generics and implemented interfaces, and does not allow the primitive modifier on interfaces or enums.

That's a reading of work in progress, not a finished language specification. The Java 28 marker in the code isn't a release promise, and the discussion didn't identify a JEP for primitive classes. I'd wait for a formal proposal before relying on the details.

Reply to this answer
_w46+torvexa.8

I'd be careful about importing assumptions from older Valhalla designs. The same term has appeared in earlier models, but that doesn't establish that the current work has identical rules for nullability, layout, or how these types interact with references.

The change seems to connect primitive classes to value classes, but that alone doesn't settle all those questions. Some readers inferred restrictions on reference fields and a relationship between equals and ==. Others disputed those interpretations, so neither is a safe conclusion from the discussion.

c.584~drivmexa:

So this isn't enough to say whether a primitive class can contain a reference field?

_g84!plendaro.6:

Right. The discussion raises that possibility, but it doesn't establish the rule clearly enough to treat it as settled.

Reply to this answer
Nuvravo-6k

Nullability needs a bit of care here. An int variable can't hold null, but Java will compile an assignment from a null Integer because it inserts unboxing. That assignment then throws a NullPointerException at runtime.

That explains the existing primitive and wrapper behavior. It doesn't by itself prove exactly how nullability will work for the proposed primitive classes.

Reply to this answer
5J!Morvani.x29

There's also a naming wrinkle. The code suggests primitive class names should start with a lowercase letter, like existing primitive type names. That's unusual for a Java class, and not everyone likes the idea.

Whether that convention survives, and what it signals about equality, still looks open from the material discussed.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions