Arrays.copyOf does not work with value type arrays

David Simms david.simms at oracle.com
Wed Mar 15 15:29:16 UTC 2017


Hi Tobias,

So this is a method handle issue, i.e. javac generates:

invokedynamic #29,  0             // InvokeDynamic #0:copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;

For call to "public static <T> T[] copyOf(T[] original, int newLength)".

This is something of a problem here. MVT array method handles return 
Object as the array.

So I'm not sure you can call Arrays.copyOf with "[QPoint" as you are 
doing here.

Furthermore, method handle JDK runtime support for Q types is incomplete.

/David Simms

On 15/03/2017 3:51 p.m., Tobias Hartmann wrote:
> import java.util.Arrays;
>
> __ByValue final class Point {
>      final int x;
>      final int y;
>
>      private Point(int x, int y) {
>          this.x = x;
>          this.y = y;
>      }
>
>      public static Point createPoint(int x, int y) {
>          return __Make Point(x, y);
>      }
> }
>
> public class Test {
>
>    public static void main(String[] args) {
>      Point[] src = new Point[10];
>      Point[] dst = Arrays.copyOf(src, 10);
>    }
>
> }




More information about the valhalla-dev mailing list