`
fuhuijun
  • 浏览: 30766 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

java反射

 
阅读更多
public class Program {
	public String str = "Hello";

	public Program() {
	}

	public Program(String str, Date date, int i) {
		this.str = str;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}

	public static void main(String[] args) throws  SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
		Program program = new Program();
		Class progClass = program.getClass();
		Field strField = progClass.getField("str");
		strField.set(program, "World");
		System.out.println(program.str);
	}

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics