日期:2014-05-17 浏览次数:20630 次
private int id; private String name; private int age; private String sex; private String address; private Date birthday;
private String name; private int age;
public class Test { public static void main(String[] args) throws Throwable { final String outname = "test"; final int outage = 123; Object o = new Object() { //匿名内部类 String name; int age; {name = outname; age = outage; } public void test() { System.out.printf("%s,%d", name, age); } }; Class<?> c = o.getClass(); //但是这样只能用反射的方式来访问 Method m = c.getDeclaredMethod("test"); m.invoke(o); } }