Fwd: State of Valhalla: array conversions

Brian Goetz brian.goetz at oracle.com
Mon Dec 16 18:02:04 UTC 2019

Received through the -comments list.

The simpler answer is: there is no conversion of form here.  The 
notation `X <: Y` means "X is a subtype of Y", or, more simply, "X is-a 
Y."  So there's no copying or loss of identity; the structure and 
identity are the same before and after the widening, just as with 
`Runnable[] <: Object[]`.

-------- Forwarded Message --------
Subject: 	State of Valhalla: array conversions
Date: 	Mon, 16 Dec 2019 18:08:07 +0100
From: 	Gernot Neppert <gneppert at web.de>
To: 	valhalla-spec-comments at openjdk.java.net


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-dev mailing list