Methodhandle (method handle) One of the series: Methodhandle and Methodtype

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.