[External] : Re: JEP 401 -- reflection and class literals

Brian Goetz brian.goetz at oracle.com
Wed Jun 30 14:51:27 UTC 2021

> Sorry, I don't know what to make of your latest reply - maybe I'm not 
> expressing myself clearly.
> What I was referring to was that, until quite recently, the proposal 
> (1) said that T.class should denote the non-nullable type for a 
> value-favoring primitive class and the nullable type for a 
> reference-favoring one.
> The latest propsal (2) suggests to have T.class always refer to the 
> nullable type. Right?

Yes, but I think even thinking of it as "the nullable type" is probably 
the wrong mental model.  It is the _unrestricted projection of the 
class_.  There's only one class -- Point -- which has two ways to store 
its objects.  All instances are instances of Point, regardless of how 
they're stored.  No object is an instance of Point.ref or of Point.val; 
you're an instance of *Point*, stored either directly or by reference.

> Now, for our famous value-favoring primitive type Point,
> the most common usecase will be methods such as transform(Point pt);
> Less common will be methods such as move(Point.ref pt) that require 
> some additional thinking & typing.
> With the proposal (1):
> In reflective code, the common usecase of finding "transform" would 
> simply require Point.class.getMethod("transform", Point.class),
> whereas finding "move" would require some more afterthought, either 
> Point.class.getMethod("move", Point.ref.class) or 
> Point.class.getMethod("move", Point.class.asIdentityClass()).
> This looks consistent to me.
> With the new proposal (2):
> In reflective code, the common usecase of finding "transform" would 
> now require either Point.class.getMethod("transform", Point.val.class) 
> or Point.class.getMethod("move", Point.class.asPrimitiveClass()).
> This strikes me as inconsistent, and that's all there is to it :)

The problem is the language, JVM, and reflection views are subtly 
different, so there is no avoiding inconsistency.  The only question is 
where to put it so as to minimize the damage.

More information about the valhalla-spec-observers mailing list