Reflection? What is it? Talking about reflection

Source: Internet
Author: User

When I first learned to reflect, I had a little bit of an understanding of what reflection was, and then I looked into it.

What is reflection?

1 Definition:

JAVA Reflection The definition I give it is a method of dynamically invoking an object, or dynamically acquiring an object's properties
I checked the introduction of Baidu
Edit
The Java reflection mechanism is in the running state, for any class, can know all the properties and methods of this class, for any one object, can call any of its methods and properties; This dynamically acquired information and the ability to dynamically invoke the object's methods are called the reflection mechanisms of the Java language. Java Reflection (emission) mechanism: "When a program is run, it is allowed to change the program structure or variable type, which is called Dynamic language." But Java has a very prominent dynamic-related mechanism: Reflection, in Java, refers to the classes that we can load, detect, and use completely unknown during compilation at runtime. In other words, a Java program can load a runtime to know the name of a class, learn its full construct (but not including the methods definition), and generate its object entities, or set values on its fields, or evoke its methods. This is a description of Baidu about him a little bit around anyway basically is a beginning to define the description below is a description of the reflection from
PublicClassDemo2_reflect {/*** Juicer (Juicer) Juice case * fruit (Fruit) apple (apple) banana (Banana) orange (orange) Juice (squeeze) *@throwsException*/PublicStaticvoid Main (string[] args)ThrowsException {/*Juicer j = new Juicer (); J.run (New Apple ()); J.run (New Orange ());*/BufferedReader br =New BufferedReader (New FileReader ("Config.properties"));//Create an input stream object, associate the configuration file class<?> clazz = Class.forName (Br.readline ());//Reads a line of contents of the configuration file, gets the bytecode object of the class Fruit F = (Fruit) clazz.newinstance ();//Creating an instance object from a byte-code object Juicer J =NewJuicer (); J.run (f); } }Interface Fruit {//Define an interfacePublicvoidSqueeze (); }Class AppleImplements Fruit {// Define an Apple class inheritance interface void Squeeze () {System.out.println ("squeeze out a cup of apple juice" Span style= "color: #000000;" >); }} class Orange implements Fruit {// defines an orange class inheritance interface public void Squeeze () {System.out.println ("squeeze out a glass of orange juice" ); }} class Juicer {//public void  run (Fruit f) {F.squeeze ();}}          

Reflection? What is it? Talking about reflection

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.