Authors who read this article recommend that you understand Java reflection and dynamic proxies first. JAVA7 introduces a new API for indirect calling methods, the most critical of which is the Java.lang.invoke package, the method handle. We can be seen as an upgraded version of Java reflection, but it does not reflect that sometimes it looks long and heavy rough. The method handle first involves two important classes, Methodhandle and Methodtype.
methodhandle It is a reference to the type of the directly executed method (or domain, constructor method, and so on), or it is an object that has the ability to safely invoke the method. In other words, we can directly invoke the underlying method referenced by the handle by means of a handle. In effect, method handles are similar to methods in reflection, but method handles are more powerful, use more flexible, and perform better.
MethodtypeIt is an immutable object that represents the type of the method signature. Each method handle has a Methodtype instance that indicates the return type and parameter type of the method. Its type is entirely determined by the parameter type and the method type, and does not relate to the name of the underlying method it refers to and the class in which it resides. For example, the length method of the string class is the same as the type of the method handle for the Intvalue method of the integer class, because both methods have no parameters and the return value type is int. Then we can get the same method type by using the following statement: Methodtype MT = Methodtype.methodtype (int.class); An object instance of Methodtype can only be created by a static factory method in the Methodtype class, and all object instances of the Methodtype class are immutable, similar to the String class. If you modify the information in the Methodtype instance, another Methodtype instance is generated. Reference: Java Programmer's Way of cultivation, deep understanding of Java7 core technologies and best practices
Methodhandle (method handle) One of the series: Methodhandle and Methodtype