Java Code Examples for java.lang.invoke.MethodHandles#arrayElementVarHandle()
The following examples show how to use
java.lang.invoke.MethodHandles#arrayElementVarHandle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VarHandleTestAccessChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessChar.class, "final_v", char.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessChar.class, "v", char.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessChar.class, "static_final_v", char.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessChar.class, "static_v", char.class); vhArray = MethodHandles.arrayElementVarHandle(char[].class); }
Example 2
Source File: VarHandleTestAccessFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessFloat.class, "final_v", float.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessFloat.class, "v", float.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessFloat.class, "static_final_v", float.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessFloat.class, "static_v", float.class); vhArray = MethodHandles.arrayElementVarHandle(float[].class); }
Example 3
Source File: VarHandleTestMethodTypeBoolean.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeBoolean.class, "v", boolean.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeBoolean.class, "static_final_v", boolean.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeBoolean.class, "static_v", boolean.class); vhArray = MethodHandles.arrayElementVarHandle(boolean[].class); }
Example 4
Source File: VarHandleTestMethodTypeInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeInt.class, "final_v", int.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeInt.class, "v", int.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeInt.class, "static_final_v", int.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeInt.class, "static_v", int.class); vhArray = MethodHandles.arrayElementVarHandle(int[].class); }
Example 5
Source File: VarHandleTestAccessInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessInt.class, "final_v", int.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessInt.class, "v", int.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessInt.class, "static_final_v", int.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessInt.class, "static_v", int.class); vhArray = MethodHandles.arrayElementVarHandle(int[].class); }
Example 6
Source File: VarHandleTestMethodTypeFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeFloat.class, "final_v", float.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeFloat.class, "v", float.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeFloat.class, "static_final_v", float.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeFloat.class, "static_v", float.class); vhArray = MethodHandles.arrayElementVarHandle(float[].class); }
Example 7
Source File: VarHandleTestMethodHandleAccessDouble.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessDouble.class, "final_v", double.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessDouble.class, "v", double.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessDouble.class, "static_final_v", double.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessDouble.class, "static_v", double.class); vhArray = MethodHandles.arrayElementVarHandle(double[].class); }
Example 8
Source File: VarHandleTestMethodHandleAccessByte.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessByte.class, "v", byte.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessByte.class, "static_final_v", byte.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessByte.class, "static_v", byte.class); vhArray = MethodHandles.arrayElementVarHandle(byte[].class); }
Example 9
Source File: VarHandleTestAccessString.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessString.class, "final_v", String.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessString.class, "v", String.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessString.class, "static_final_v", String.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessString.class, "static_v", String.class); vhArray = MethodHandles.arrayElementVarHandle(String[].class); }
Example 10
Source File: VarHandleTestMethodTypeDouble.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeDouble.class, "final_v", double.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeDouble.class, "v", double.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeDouble.class, "static_final_v", double.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeDouble.class, "static_v", double.class); vhArray = MethodHandles.arrayElementVarHandle(double[].class); }
Example 11
Source File: VarHandleTestMethodHandleAccessFloat.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessFloat.class, "final_v", float.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessFloat.class, "v", float.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessFloat.class, "static_final_v", float.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessFloat.class, "static_v", float.class); vhArray = MethodHandles.arrayElementVarHandle(float[].class); }
Example 12
Source File: VarHandleTestAccessDouble.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessDouble.class, "final_v", double.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessDouble.class, "v", double.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessDouble.class, "static_final_v", double.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestAccessDouble.class, "static_v", double.class); vhArray = MethodHandles.arrayElementVarHandle(double[].class); }
Example 13
Source File: VarHandleTestMethodTypeLong.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeLong.class, "final_v", long.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeLong.class, "v", long.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeLong.class, "static_final_v", long.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeLong.class, "static_v", long.class); vhArray = MethodHandles.arrayElementVarHandle(long[].class); }
Example 14
Source File: VarHandleTestMethodHandleAccessChar.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessChar.class, "final_v", char.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessChar.class, "v", char.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessChar.class, "static_final_v", char.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessChar.class, "static_v", char.class); vhArray = MethodHandles.arrayElementVarHandle(char[].class); }
Example 15
Source File: VarHandleTestMethodTypeShort.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeShort.class, "final_v", short.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeShort.class, "v", short.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeShort.class, "static_final_v", short.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodTypeShort.class, "static_v", short.class); vhArray = MethodHandles.arrayElementVarHandle(short[].class); }
Example 16
Source File: VarHandleTestMethodHandleAccessInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessInt.class, "final_v", int.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessInt.class, "v", int.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessInt.class, "static_final_v", int.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessInt.class, "static_v", int.class); vhArray = MethodHandles.arrayElementVarHandle(int[].class); }
Example 17
Source File: VarHandleTestMethodHandleAccessBoolean.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@BeforeClass public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class); vhField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessBoolean.class, "v", boolean.class); vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessBoolean.class, "static_final_v", boolean.class); vhStaticField = MethodHandles.lookup().findStaticVarHandle( VarHandleTestMethodHandleAccessBoolean.class, "static_v", boolean.class); vhArray = MethodHandles.arrayElementVarHandle(boolean[].class); }
Example 18
Source File: TestSolutionGetter.java From java-katas with MIT License | 4 votes |
@Test @Tag("PASSING") @Order(6) public void getPrimitiveArrayFromConstructedClassViaVarHandles() { try { /* * DONE: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.privateLookupIn(?, ?) * HINT: params are Target class, Lookup type * Check API: java.lang.invoke.MethodHandles.Lookup.findVarHandle(?, ?, ?) * HINT: params are Declaring class, Variable name, Variable type */ VarHandle privatePrimitiveArrayVariableVarHandle = MethodHandles .privateLookupIn(TestSolutionGetter.class, MethodHandles.lookup()) .findVarHandle(TestSolutionGetter.class, "privatePrimitiveArrayVariable", int[].class); assertEquals(1, privatePrimitiveArrayVariableVarHandle.coordinateTypes().size(), "There should only be one coordinateType"); assertEquals(TestSolutionGetter.class, privatePrimitiveArrayVariableVarHandle.coordinateTypes().get(0), "The only coordinate type is AttributeGetterTest"); int[] varHandleTypeArray = int[].class.cast( privatePrimitiveArrayVariableVarHandle.get(this)); /* * TODO: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.arrayElementVarHandle(?) */ VarHandle arrayElementHandle = MethodHandles.arrayElementVarHandle(int[].class); assertEquals(3, varHandleTypeArray.length, "The length of the array should be 3"); assertEquals(1, arrayElementHandle.get(privatePrimitiveArrayVariable, 0), "The first element of the array should be 1"); assertEquals(3, arrayElementHandle.get(privatePrimitiveArrayVariable, 2), "The third of the array should be 3"); } catch (NoSuchFieldException | IllegalAccessException | NullPointerException e) { fail(TEST_FAILURE.getValue() + e.getMessage()); } }
Example 19
Source File: TestKataGetter.java From java-katas with MIT License | 4 votes |
@Test @Tag("TODO") @Order(8) public void get2DimensionalPrimitiveArrayFromConstructedClassViaVarHandles() { try { /* * TODO: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.privateLookupIn(?, ?) * HINT: params are Target class, Lookup type * Check API: java.lang.invoke.MethodHandles.Lookup.findVarHandle(?, ?, ?) * HINT: params are Declaring class, Variable name, Variable type */ VarHandle privatePrimitive2DArrayVariableVarHandle = MethodHandles .privateLookupIn(null, null) .findVarHandle(null, null, null); assertEquals(1, privatePrimitive2DArrayVariableVarHandle.coordinateTypes().size(), "There should only be one coordinateType"); assertEquals(TestKataGetter.class, privatePrimitive2DArrayVariableVarHandle.coordinateTypes().get(0), "The only coordinate type is AttributeGetterTest"); int[][] varHandleTypeArray = int[][].class.cast( privatePrimitive2DArrayVariableVarHandle.get(this)); /* * TODO: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.arrayElementVarHandle(?) */ VarHandle arrayElementHandle = MethodHandles.arrayElementVarHandle(null); assertEquals(3, varHandleTypeArray.length, "The length of the array should be 3"); assertEquals(1, ((int[]) arrayElementHandle.get(privatePrimitive2DArrayVariable, 0))[0], "The first element of the array should be 1"); assertEquals(9, ((int[]) arrayElementHandle.get(privatePrimitive2DArrayVariable, 2))[2], "The last element of the array should be 9"); } catch (NoSuchFieldException | IllegalAccessException | NullPointerException e) { fail(TEST_FAILURE.getValue() + e.getMessage()); } }
Example 20
Source File: TestSolutionGetter.java From java-katas with MIT License | 4 votes |
@Test @Tag("PASSING") @Order(8) public void get2DimensionalPrimitiveArrayFromConstructedClassViaVarHandles() { try { /* * DONE: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.privateLookupIn(?, ?) * HINT: params are Target class, Lookup type * Check API: java.lang.invoke.MethodHandles.Lookup.findVarHandle(?, ?, ?) * HINT: params are Declaring class, Variable name, Variable type */ VarHandle privatePrimitive2DArrayVariableVarHandle = MethodHandles .privateLookupIn(TestSolutionGetter.class, MethodHandles.lookup()) .findVarHandle(TestSolutionGetter.class, "privatePrimitive2DArrayVariable", int[][].class); assertEquals(1, privatePrimitive2DArrayVariableVarHandle.coordinateTypes().size(), "There should only be one coordinateType"); assertEquals(TestSolutionGetter.class, privatePrimitive2DArrayVariableVarHandle.coordinateTypes().get(0), "The only coordinate type is AttributeGetterTest"); int[][] varHandleTypeArray = int[][].class.cast( privatePrimitive2DArrayVariableVarHandle.get(this)); /* * TODO: * Replace the "null"s with valid values to get a VarHandle. * Check API: java.lang.invoke.MethodHandles.arrayElementVarHandle(?) */ VarHandle arrayElementHandle = MethodHandles.arrayElementVarHandle(int[][].class); assertEquals(3, varHandleTypeArray.length, "The length of the array should be 3"); assertEquals(1, ((int[]) arrayElementHandle.get(privatePrimitive2DArrayVariable, 0))[0], "The first element of the array should be 1"); assertEquals(9, ((int[]) arrayElementHandle.get(privatePrimitive2DArrayVariable, 2))[2], "The last element of the array should be 9"); } catch (NoSuchFieldException | IllegalAccessException | NullPointerException e) { fail(TEST_FAILURE.getValue() + e.getMessage()); } }