Variable handlers are typed references to variables and are governed by the java.lang.invoke.VarHandle abstract class. The VarHandle method's signature is polymorphic. This provides for great variability in both method signatures and return types. Here is a code sample demonstrating how VarHandle might be used:
. . .
class Example {
int myInt;
. . .
}
. . .
class Sample {
static final VarHandle VH_MYINT;
static {
try {
VH_MYINT =
MethodHandles.lookup().in(Example.class)
.findVarHandle(Example.class, "myInt", int.class);
}
catch (Exception e) {
throw new Error(e);
}
}
}
. . .
As you can see in the preceding code snippet, VarHandle.lookup() performs the same operation as those that are performed by a MethodHandle.lookup() method.
The aim of this change to the Java platform was to standardize the way...