日期:2014-05-20 浏览次数:21220 次
class Test11 {
    static final int staticFinal = 11;
    void show() {
        System.out.println(this.getClass().getCanonicalName());
    }
}
public class Temp {
    public static void main(String[] args) {
        Test11 test = new Test11();
        test.show();
        
        Class test1=null;
        try {
            test1=Class.forName("a10_2.Test11");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        [color=#FF0000]test1????[/color]
    }
}
package a10_2;
------解决方案--------------------
http://happyran.zbpifa.com
http://007ej.com/user.asp
------解决方案--------------------
这问题和反射有关吗
------解决方案--------------------
Class test1=null;
try {
test1=Class.forName("a10_2.Test11");//这里反射
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如果你在这里直接通过test1访问成员是访问不到了,因为没有具体实例对象,也就没有实例成员
------解决方案--------------------
用test1.getDeclaredField("staticFinal ").getInt();应该可以得到吧,可以试试...