Get the object of class:
Suppose Foo is a class, Foo foo = new Foo ();
The first type: Class c1 = Foo.class;
The second type: Class C2 = Foo.getclass ();
The third type: Class C3 = Class.forName ("Com.nudt.reflection.Foo"); Will throw an exception
At this time C1 = = C2 = = C3 is True
You can also create an instance of Foo through C1\C2\C3:
Foo foo = (foo) c1.newinstance (); Premise: Foo has a parameterless construction method
Dynamic load class (Runtime load Class):
Class C = Class.forName (class full name);
(Animal) A = (Animal) c.newinstance ();
Where animal is an interface, the class to be loaded at run time inherits the interface, and creates its own parameterless construction method
Get a Method object:
The reflection operation of the method:
Method.invoke ()
Generics in Java are protected from erroneous input, and no generics exist after compilation.
You can bypass the compilation by reflection of the method, speaking int into the list<string>
Java reflection mechanism and dynamic loading class Learning Essentials