Java Reflection Mechanism:
Testing entity Classes
Taking human as an example
/** * PROJECT:DAY12_FOR_LXY * created:lulu * DATE:2016/8/10/public class Human<t> {private String name
;
private int age;
private float height;
private static int legs = 2;
Private map<string, string> jobs;
Private T T;
public int Say () {System.out.println ("I ' m" + name);
return 0;
} private void Sleep (Human Human) {System.out.println (name + ' sleep with ' + human.name);
Public list<integer> GetList () {return new arraylist<> ();
Public Human () {} private Human (String name, int age, float height) {this.name = name;
This.age = age;
This.height = height;
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
public int getage () {return age; public void Setage (int age) {if (Age >/Age < 0) {throw new RuntimeException (' Age > 150 | |
Age < 0 ");
} This.age = age; } Public Float GEtheight () {return height;
public void SetHeight (float height) {this.height = height;
@Override public String toString () {return "human{" + "Name= '" + name + ' \ ' + ", age=" + Age +
", height=" + Height + '} ';
}
}
Test Get construct method
/** * PROJECT:DAY12_FOR_LXY * Created:lulu * DATE:2016/8/10////////* Get Construction Method/public class TestConstructor {Publ
IC static void Main (string[] args) {//get the corresponding class structure, which is used to describe Human class class
test get field
/** * PROJECT:DAY12_FOR_LXY * Created:lulu * DATE:2016/8/10/* Get Properties: properties include: ( Property name type modifier generic) The property of the parent class/public class Testfield {public static void main (string[] args) {class
test Fetch method
/** * PROJECT:DAY12_FOR_LXY * Created:lulu * DATE:2016/8/10///* Fetch method: Method name modifier Returns a call to a generic static and Non-static method of a value type * * Publi
C class TestMethod {public static void main (string[] args) {class
Test Get class Information
public static void Main (string[] args) {
printclassinfo (student.class);
}
The class of the only parent class in the public static void Printclassinfo (Class C) {
//java object
System.out.println (C.getname ());
System.out.println (C.getsimplename ());
System.out.println (C.getsuperclass ());
Class[] interfaces = C.getinterfaces ();
for (Class aninterface:interfaces) {
System.out.println (aninterface);
}
The outer class class has only two types of access permission modifiers (public and default)
int modifiers = C.getmodifiers ();
}
Thank you for reading, I hope to help you, thank you for your support for this site!