Status of array covariance in lworld branch
Ioi Lam
ioi.lam at oracle.com
Wed Dec 12 00:02:23 UTC 2018
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