State of Valhalla: array conversions

Gernot Neppert gneppert at web.de
Mon Dec 16 17:08:07 UTC 2019


Hello,

the document states that

"For any class X (inline or identity) that implements interface I, the
following subtyping relationship holds for arrays of X:

X[] <: I[] <: Object[]"

While this seems intuitive and consistent with the new
"reference-projection", it raises the question:

What kind of conversion will the assignment of an array-of-inlines to an
array-of-refs be?
Of course, a sensible one-way conversion is feasible. But then, the
array-of-refs would not be an alias of the original array anymore.

Given the following code:

int[] a = {42, 43, 4711};
Integer[] r = a;
r[1] = -1;

I'd expect the assignment r[1] = -1 to modify the original array a, too!
It's hard to imagine how that could be efficiently implemented.

Regards, Gernot




More information about the valhalla-spec-comments mailing list