标签:暴力反射
public class Q1_example { private String name="lijun"; public Q1_example(){ } public String getName() { return name; } public void setName(String name) { this.name = name; } }
public class Q1 { public static void main(String[] args) throws Exception{ Class clazz = Class.forName("Q1_example"); Object object = clazz.getConstructor(null).newInstance();//创建对象 Field field =clazz.getDeclaredField("name"); field.setAccessible(true);//开启暴力反射 field.set(object, "example");//赋值 System.out.println(field.get(object)); } }
标签:暴力反射
原文地址:http://blog.csdn.net/u010218226/article/details/46560957