Understanding of the Java reflection mechanism

Source: Internet
Author: User

The Java language provides a reflection mechanism, which also provides a way to dynamically create Java instance objects. The difference between a lot of people who create objects for new and reflection is that dynamic creation is not very understandable, because after all, even creating objects with the New keyword is actually created "dynamically" because they are created when the virtual runtime is running, so how should this dynamic creation be understood? In fact, the so-called dynamics, can be understood as in some cases, we can not modify the Java code to implement at any time "dynamic" additions and deletions of new Java objects. Now throw away the reflection mechanism, if we need new Java objects in a project, what should we do? It is, of course, obtained through new, and then the code is recompiled. If there is a reflection mechanism, we can not be so troublesome, directly on demand through the corresponding type fully qualified class name dynamically create objects and use, then the required class name how come? You can dynamically create the object instances that we need by writing the class name in the configuration file and then directly reading the configuration file. In fact, the strong spring is doing this. By the way, the spring container uses the reflection mechanism to provide us with the dynamic instance object, which is actually taking advantage of encapsulation, encapsulating the concrete implementation of the underlying reflection creation object, and we just need to pass in a parameter of the full class name to get an instance of the corresponding class.

Understanding of the Java reflection mechanism

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.