Java inline functions

Source: Internet
Author: User

previously used in C + +, know that it has an inline function concept, the general situation with the inline keyword decoration, in C + + definition class, the kind of writing in the class definition of the function, also by the compiler as an inline function processing.
    
Having said so much, I haven't said anything about inline functions. The so-called inline function refers to the function in the place where it is called directly, the compiler does not use the same as the general function, the argument stack, the return parameter out of the stack and the release of resources, which improves the program execution speed.
    
now it's time to speak Java, and there's a keyword final in the Java language to indicate that the function is inline, for example:
Java code
  1. public  final  void  dosomething ()  {  
  2. // to do something
  3. }


when called, the method will be used directly at the call, thus increasing the execution speed of the program. In addition, the final keyword has a role to prevent dosomething methods from being overwritten in subclasses, and if you want DoSomething to be a final act, it should be designed as final.
    

Inline is not necessarily good, when the method body that is specified as an inline is large, the overhead of the expansion may have exceeded the time of the normal function call, and the introduction of the inline has reduced performance because it should be prudent to select this keyword, but in later versions of the JVM the optimizations were made when the inline was processed. It determines whether the call is expanded based on the size of the method.


--------------------------------------------------------a gorgeous dividing line-------------------------------------------------------


Doug Lea's writing class library is a variety of optimization methods that will come to mind.

Java inline functions

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.