> On Jun 19, 2020, at 11:07 AM, Tobi Ajila <[email protected]> wrote:
>
> I am still a little unclear as to what the motivation is for this. Is this
> solely for specialized generics?
>
> In Dan's examples with `I` and `java/lang/Integer$val`, the only places where
> conversions are needed are when primitives are used as type parameters or to
> call instance methods on them, both of which can already be done with
> primitive arrays. So in the LW3 - LW20 timeframe would we have any need for
> these conversions? If so, could you provide some examples?
I think it comes down to specialization and subtyping.
Pre-specialization, here's one example that uses subtyping:
int[] arr = { 1 };
Object[] objs = arr; // just like Point[] <: Object[]
Object obj = objs[0];
Integer i = (Integer) obj;
This would compile to something like:
iconst_1
newarray T_INT
dup
iconst_0
iconst_1
iastore
astore_0
aload_0
astore_1
aload_1
iconst_0
aaload
astore_2
aload_2
checkcast java/lang/Integer
astore_3
Going in the other direction—allocating a [Qjava/lang/Integer; and then using
iaload/iastore on it—may not be necessary unless/until the language supports
"new T[]" in specialized code, but it tentatively makes sense to support now
anyway, rather than having to come back and fix it up later.
> In the case of specialized generics, is the intention that `[I` (and I
> suppose `I` as well) will appear in generic code?
If you mean "can '[<T>' be specialized to '[I'?", the answer is no. The
primitive types cannot act as type arguments.