From C + + to Java III (inline)

Source: Internet
Author: User

(4) All methods are defined in the body of the class. So in the eyes of C + +, it seems that all functions are embedded, but the truth is not how (the embedded problem is described later).
There is no "embed" (inline) method in Java. The Java compiler may decide to embed a method on its own, but we have no more control over it. In Java, you can use the final keyword for a method to "suggest" an embedding operation. However, embedding functions is also a recommendation for C + + compilers.

The Java member function, whether inline or not, is defined in the class-defined code, which is only the inline function in C + +. In Java, the final keyword is the difference between the inline and the final keyword, and you can "suggest" that the compiler embed the method. Whether or not the compiler will actually embed, depending on its judgment, the final keyword is just a suggestion for the person who wrote the program, or the compiler.

What is the operation of the embed operation.

Parameter into the stack, executing a copy of the function code. and C + + is the same

Final key word:

1. After the final keyword is added, the member function is locked and will not be overloaded in inheritance. (This is different from the "recommended" embedding operation)

2. The private member function is implied as final, of course, if willing to give private members plus final keyword is also allowed, but there will be no additional effect.

3. Because private member functions do not actually act as inherited interfaces, there is no question of how to dispose of overloaded private final functions.

4. The final keyword is added to a class, which means that the class is not allowed to be modified and inherited; With the final class, the function members are implicitly final, without having to add the final keyword to the function separately.

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.