Person thisPerson = null;
thisPerson = new Person();
两句加起来就等于:
Person  thisPerson=new Person();
一般后者是用于定义一个类的实例并马上初始化。然后就可以使用了。
前者一般是你已经有了这个类的实例,但是想要换个名字使用,比如已经有个一个
Person类型的变量:thatPerson
这时候你就可以
Person thisPerson = null;
...//code
thisPerson = thatPerson;
...//code

解决方案 »

  1.   

    例如你不能在一开始就确定如何实例化这个引用,需要在一个方法内给这个引用实例化,而你需要在另一个方法中使用这个引用,那么你必须将他声明在一个公共区块内而不能在第一个方法内,不然编译会通不过。
    eg
    Class a{
      //……
      Person thisPerson = null;  public void init(){
        thisPerson = new Person();
        //……
      }  public void usePerson(){
        thisPerson.move();
        //……
      }
    //……
    }