Evolving the wrapper classes

Brian Goetz brian.goetz at oracle.com
Wed Jun 17 22:45:06 UTC 2020


> Hmm, just maybe this will be less confusing than I was fearing. I'm 
> seeing now that "Integer is the real class, int is alias for 
> Integer.val" is a whole lot cleaner than "int becomes a val-default 
> class and Integer is demoted to alias for int.ref", which for some 
> reason was the way I was thinking of it.

I'm sure that, sometime during the evolution, I probably said it the way 
you remember.  Then Dan came along and cleaned it up :)

>
>
>
>     Java language/compiler changes (when --enable-preview is set):
>     - The class file reader knows how to find the special
>     Integer.class and Integer$val.class.
>     - The type 'Integer.val' is equivalent to 'int'. Primitive types
>     are inline types—they have members, support method invocation, etc.
>
>
> This at least /suggests /that `42L.hashCode()` would begin to work 
> just as `"foo".hashCode()` does?

We certainly have that option.  We could decide to not take it, on the 
theory that it scares the neighbors, but it does seem sensible to just 
say "0L is a long-valued expression" and "long implements XYZ 
interfaces", and let the neighbors be scared for a few minutes.

> Users /can/ write `Integer.val` in their code, but would there ever be 
> a good reason to? I assume we would always prefer `int`. And this 
> actually makes me wonder if it's worth considering also allowing 
> `int.ref` to be an alias for `Integer` because it would allow users to 
> drop the word `Integer` from their code more completely, and therefore 
> `int` would look more and more like it was just an inline type like 
> any other. It reminds you that the old boxing/unboxing isn't in play 
> anymore. And `int.ref` is more self-evidently something you can't 
> synchronize on, etc. But, what would remain weird is that you don't 
> /actually /find a val-default class called `int` sitting in an 
> `int.java` file.

Right, there's a set of pros and cons here, none of which are 
technical.  Being able to say `int.ref` makes it more clear that `int` 
and `Point` are the same thing, but on the other hand, it raises issues 
of "there are two ways to say the same thing, so let's have an endless 
debate about it."


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/valhalla-spec-experts/attachments/20200617/f8500216/attachment-0001.htm>


More information about the valhalla-spec-experts mailing list