Status of array covariance in lworld branch
Srikanth
srikanth.adayapalam at oracle.com
Wed Dec 12 00:30:26 UTC 2018
Javac has had no changes going in for co-variance so far. I have
addressed the several others I have been working on so far and I am
ready to take this up now -
I'll let Brian comment on your understanding to confirm that it matches
the present plan of record.
Thanks!
Srikanth
On 12/12/18 5:32 AM, Ioi Lam wrote:
> As far as I understand, the plan is to not support covariance between
> Object and value arrays. So I wrote a test case to see what's the
> current behavior. Can anyone tell me if my understanding is correct?
>
>
> import java.util.Arrays;
>
> public class Test {
> static final value class V {
> public final int v1;
> private V () {v1 = 0;}
> }
>
> public static void main(String args[]) {
> Object oa[] = new Object[1];
> oa[0] = V.default;
> V va[] = new V[1];
> va[0] = V.default;
>
> System.out.println("Object[].class.isInstance(va) = " +
> Object[].class.isInstance(va));
>
> Object oa2[] = va; // <-- javac should reject, but doesn't
> va = (V[])oa2; // <-- javac should reject(?), but doesn't
>
> V[] va2 = Arrays.copyOf(oa, oa.length, V[].class);
> System.out.println("va = " + va);
> System.out.println("va2 = " + va2);
> }
> }
>
>
> $ java -cp . -XX:+EnableValhalla Test
> Object[].class.isInstance(va) = true // should be false
> va = [QTest$V;@372f7a8d
> va2 = [QTest$V;@2f92e0f4 // should be [LObject;
>
>
> Thanks
> - Ioi
More information about the valhalla-dev
mailing list