fork download
  1. import static java.lang.invoke.MethodHandles.*;
  2. import static java.lang.invoke.MethodType.*;
  3.  
  4. import java.lang.invoke.MethodHandle;
  5. import java.util.Arrays;
  6.  
  7. class Ideone
  8. {
  9. public static void main(String[] args) throws Throwable {
  10. MethodHandle MH_arrayClone = publicLookup()
  11. .findVirtual(int[].class, "clone", methodType(Object.class))
  12. .asType(methodType(int[].class, int[].class)); // convenient cast return type
  13.  
  14. System.out.println(System.getProperty("java.version"));
  15.  
  16. int[] a = { 1, 2, 3, 4 };
  17. int[] b = (int[]) MH_arrayClone.invokeExact(a);
  18.  
  19. System.out.println(Arrays.toString(a));
  20. System.out.println(Arrays.toString(b));
  21. }
  22. }
Success #stdin #stdout 0.13s 32712KB
stdin
Standard input is empty
stdout
1.8.0_112
[1, 2, 3, 4]
[1, 2, 3, 4]