A method handle is a typed, directly executable reference to an underlying method, constructor, field, or similar low-level operation, with optional transformations of arguments or return values.
/*** Produces a method handle giving read access to a non-static field.* The type of the method handle will have a return type of the field's* value type.* The method handle's single argument will be the instance containing* the field.*/publicMethodHandlefindGetter(Class<?> refc,String name,Class<?> type)
/*** Produces a method handle giving write access to a non-static field.* The type of the method handle will have a void return type. * The method handle will take two arguments, the instance containing* the field, and the value to be stored.*/publicMethodHandlefindSetter(Class<?> refc,String name,Class<?> type)
classHorse {publicvoidrace() {System.out.println("Horse.race()"); }}classDeer {publicvoidrace() {System.out.println("Deer.race()"); }}classCobra {publicvoidrace() {System.out.println("How do you turn this on?"); }}