java反射删除类属性_java反射操作类⽅法与属性package st;
public class Ur {
innocence
private int age;
private String email;
private String urname;
public Ur() {
}
public Ur(int age, String email, String urname) {
this.age = age;
拉丁文化ail = email;
this.urname = urname;
}
public int getAge() {
return age;
}
public void tAge(int age) {
this.age = age;
}
public String getEmail() {
邮递员的英文
return email;
}
public void tEmail(String email) {
}
public String getUrname() {
return urname;
}
public void tUrname(String urname) {
this.urname = urname;
}
}siren
package st;
import flect.Constructor;
import flect.Field;
import flect.InvocationTargetException;
import flect.Method;
public class TtF {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
Class clazz = (Class) Class.forName("st.Ur");new directions
英文字母顺序表Field urname = DeclaredField("urname");
System.out.Name());
/**
* ⽆参构造⽅法声明⼀个实例
*/
Ur ur = wInstance();
Method method = DeclaredMethod("tUrname", String.class);
method.invoke(ur, "alex");
System.out.Urname());
/**
* 有参构造⽅法声明实例
教务处英文
* 第⼀步:找到构造⽅法,第⼆个利⽤构造⽅法来实例对象
*/
Constructor constructor = DeclaredConstructor(int.class,String.class,String.class);
Ur u2 = wInstance(10,"","MarCus");
告饶System.out.Urname());
// 声明第三个实例
bbc广播Ur u3 = wInstance();
Field field = DeclaredField("age");
field.tAccessible(true);
field.t(u3,100); //数据类型要保持⼀致
System.out.Age());omega和alpha什么意思
}
}