PrimitiveObject interface

Dan Smith daniel.smith at
Tue Jan 5 19:11:07 UTC 2021

A design change I'd like to propose: in addition to the IdentityObject interface, let's have a complementary PrimitiveObject interface. Like IdentityObject, the PrimitiveObject interface can be extended/implemented explicitly or, sometimes, implicitly.

Some language rules:
- Every primitive class implicitly implements PrimitiveObject (this is new)
- Every non-primitive concrete class implicitly implements IdentityObject (this is not new)
- Certain abstract classes (e.g., those with fields) implicitly implement IdentityObject (this is not new)
- All other abstract classes, interfaces, and Object implement neither interface by default
- Arrays implement IdentityObject
- It's an error for a class or interface to extend both interfaces (extending neither, if you're an interface or abstract class, is fine)

This leaves us with every object implementing exactly one of those two interfaces.

We've wondered whether there are use cases to justify the second interface. Having gained some experience in this system, I think it's safe to say there will be. For example, an abstract class or interface extended by a family of primitive classes may wish to explicitly implement PrimitiveObject as a way to communicate a particular performance model, immutability, etc., to clients. Or certain primitive-like features, like operator overloading, may interact with libraries through type variables that extend PrimitiveObject. I also like the symmetry, which avoids any biasing of one side over the other.

Revised JVM behavior:
- Primitive classes either get PrimitiveObject as an injected superinterface or reject classes without that superinterface. (Which one? TBD.)
- Non-primitive concrete classes get IdentityObject as an injected superinterface. (Not possible to just reject classes here, due to legacy class files.)
- Abstract classes may be declared to support primitive subclasses (this is a separate mechanism). If an abstract class does not opt in to primitive subclasses, it gets IdentityObject as an injected superinterface.
- Arrays have IdentityObject as a supertype
- It's a (load-time?) error for a class or interface to extend both PrimitiveObject and IdentityObject

More information about the valhalla-spec-observers mailing list