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