Binding of Java method calls

Source: Internet
Author: User

Connecting a method call to the same method body is called a "binding" (Binding). If the binding (by the compiler and the linker, if any) is performed before the program is run, it is called early binding. You may never have heard of this term before, because it is impossible in any programmed language. The C compiler has only one method invocation, that is, "early binding."

The most puzzling part of the above program is all about early binding, because the compiler does not know exactly which method to call if it has only one instrument handle.

The workaround is "late binding," which means that the binding takes place during run time, based on the type of object. Late binding is also called "Dynamic binding" or "run-time binding." If a language implements late binding, it must also provide mechanisms to determine the type of the object during run time, and to invoke the appropriate method, respectively. In other words, the compiler still does not know the type of object at this time, but the method invocation mechanism can investigate itself to find the correct method body. Different languages differ in how they are implemented in late binding. But we can at least think of it as: they all have special types of information to be placed in the object.

All the methods that are bound in Java adopt late-binding techniques, unless a method has been declared final. This means that we don't usually have to decide whether to have late binding-it happens automatically.
Why should a method be declared final? As noted in the previous chapter, it prevents others from overwriting that method. But perhaps more importantly, it can effectively "turn off" dynamic binding, or tell the compiler that it does not need to be dynamically bound. This allows the compiler to generate more efficient code for the final method call.

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.