关于this主要指代一个非静态类实例,建议先搞清楚类和实例的关系.//-------UseThis.java-------------public class UseThis { String name = null; public UserThis() { }//end constructor public void doit() { this.name = "00123"; //等价于name = "00123"; }//end doit
}//另一个例子 public class OtherUse { static String name = null; //注意这个声明为static public UserThis() { }//end constructor public void doit() { OtherUser.name = "00123"; //等价于name = "00123"; }//end doit
this指对该类本身的引用!有时是为了区别成员变量和局部变量!
2. this 表示本身.用它能看到自己和自己的子类.
//等价于name = "00123"; }//end doit
}//另一个例子
public class OtherUse { static String name = null; //注意这个声明为static public UserThis() { }//end constructor public void doit() { OtherUser.name = "00123";
//等价于name = "00123"; }//end doit
}
而seward() 说:void 就是没有返回植,其他的就是有返回植, 在写函数的时候如果不需要得到任何结果就用void .
小弟愚笨,我又糊涂了,希望可以有举例说明。
this指的是对类本身的引用;
System.gc();进行垃圾回收;