如题,看看,下面的代码不会异常,为什么?
class A {
    private int m_test = 0;
    private static B m_testb = (new A()).new B();    public static void main( String[] args){
        m_testb.run();
        System.out.println(" this is null");
    }
    
    class B{
        public void run(){
            m_testb = null;
            System.out.println("I'm null");
            print();
        }
        private void print(){
            System.out.println( "I'm print");
        }
    }
}

解决方案 »

  1.   

    晕,,你这里m_testb 不是通过(new A()).new B();赋值了吗?当然不是空了,
      

  2.   

    to dulang200x(独狼):
    请仔细看run方法。
      

  3.   

    我是这样认为的,Jvm 在调用的时候,另外使用临时变量来引用当前的对象。所以m_testb = null 时,print()方法仍然可以正常运行。
      

  4.   

    楼主是不是想说m_testb = null;也晕
      

  5.   

    m_testb只是个引用而已。置null并不会马上释放对象。
    而是对象没有人引用时才可能会被释放你在print();后 System.out.println(this); //this也是引用