Clarification needed about primitive wrappers?
daniel.smith at oracle.com
Fri Jul 10 16:36:35 UTC 2020
> On Jul 10, 2020, at 6:53 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> From valhalla-spec-observers,
> ----- Mail original -----
>> De: "Gernot Neppert" <mcnepp02 at googlemail.com>
>> À: "Valhalla Expert Group Observers" <valhalla-spec-observers at openjdk.java.net>
>> Envoyé: Vendredi 10 Juillet 2020 12:06:32
>> Objet: Clarification needed about primitive wrappers?
>> it seems some clarification is needed about the fate of the primitive
>> wrappers in "Valhalla-world".
>> In this and the related Mailing Lists, you can find the following two
>> proposals, with subtle differences:
>> 1. the primitive wrappers (java.lang.Integer etc) are designated to become
>> inline classes. This idea has been most recently cited in the posting
>> "Identity warnings for inline class candidates".
>> 2. the primitive wrappers should become the reference-projections of
>> corresponding inline classes. This has sometimes been augmented with the
>> idea that the denominations for the primitive types (such as "int") will
>> then become aliases for those new inline types.
>> So, what's it going to be?
This question reflects some confusion about the concepts (understandable, given the evolution of the concepts; but I think they're stable as of a few months ago).
A class may be declared 'inline', which indicates that its instances have no identity. The instances of that class may be treated as values in two ways:
1) As inline objects
2) As references to objects
It's the same object in both cases, just handled in different ways.
There are, correspondingly, two types:
1) An inline type
2) A reference type
A "reference projection" is a way to think about (and, in our compilation strategy, implement) the reference type. But, in the language model, it's a *type*, not a *class* (or interface). A better way to think about it is that there is a single class with two corresponding types.
Typically, for an inline class 'Foo', the inline type is spelled 'Foo' and the reference type is spelled 'Foo.ref'.
For some inline classes, the declaration will indicate that the inline type is spelled 'Foo.val' and the reference type is spelled 'Foo'.
In the case of java.lang.Integer: it will be declared as an inline class. The inline type will be spelled 'int' (and perhaps also 'Integer.val'). The reference type will be spelled 'Integer' (and perhaps also 'int.ref'). The only special thing here is the interpretation of the keyword 'int'. (Well, and lots of compilation magic under the hood.)
The Identity Warnings JEP sidesteps much of this discussion by making no mention of types—it's only concerned with the classes and the changing behaviors of their instances.
More information about the valhalla-spec-experts