Who called the Invoke method in the Invocationhandler?

Source: Internet
Author: User

The key issue is their intrinsic connection. Although you can look at the source code, including the class library. But to abstract them out helps to understand.

In the customer class (that is, the client class for the following code), statement manager managerproxy=
(Manager) Proxy.newproxyinstance (Managerimpl.getclass (). getClassLoader (), Managerimpl.getclass (). GetInterfaces (), Securityhandler);

As you can see, the Newproxyinstance method in the proxy (library Class) is invoked, which returns an instance of the proxy object and then transitions up to its corresponding interface.

The problem is what the method has done before it returns. Let's look at the third of its arguments: Securityhandler, which is an instance of the Invocationhandler interface implementation class: Securityhandler. Because there is an invoke method in the Invocationhandler interface, the implementation class certainly needs to implement this method, that is, its implementation class (This is the Businesshandler Class) has an Invoke method, and if the Invoke method is to be invoked, Can only be invoked through the Businesshandler class object.

In the following source code class Proxy0, there are three places that have already invoked the Invoke method with Businesshandler class objects, respectively, in the codes of these methods: Publicfinalbooleanequals (Objectobj) ; Publicfinalinthashcode (); publicfinalstringtostring (). You may have a question, this method also does not see where to be Proxy0, there are three places have already used Businesshandler class object to invoke Invoke method, they are in the code of these methods respectively: Publicfinal Boolean equals ( Object obj), public final int hashcode (), Public final String toString (). You may have a question, this method also did not see where to be called by the Proxy0 object, how can execute Invoke method? But please look at the Proxy0.

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.