谁说的? this 为什么不能 = null ?cannot assign a value to final variable this 是谁定义的 final this ? 我的 eclipse 和 jbuilder 都可以编译阿。下面是我的代码: public class TestIsNull { /** * */ public TestIsNull() { super(); // TODO Auto-generated constructor stub } public void destroy(){ this = null; } public static void main(String args[]){ TestIsNull b = new TestIsNull(); System.out.println(b); b.destroy(); System.out.println(b); } } 我觉得奇怪的是,打印出来 dao.TestIsNull@126b249 dao.TestIsNull@126b249为什么第二个没有变成 null ? 如果把 b.destroy() 改为 b = null. 打印结果就是 dao.TestIsNull@126b249 null 哪位达人给解释一下???
this根本就不应该允许被赋值为null public void destroy(){ this = null;//你要注意,实际上你的类是存在的。this根本就不能够被改变 //所以就算它能够编译通过,这句话根本就不会有任何作用 }
public class TestIsNull { /**
*
*/
public TestIsNull() {
super();
// TODO Auto-generated constructor stub
}
public void destroy(){
this = null;
}
public static void main(String args[]){
TestIsNull b = new TestIsNull();
System.out.println(b);
b.destroy();
System.out.println(b);
}
}
我觉得奇怪的是,打印出来
dao.TestIsNull@126b249
dao.TestIsNull@126b249为什么第二个没有变成 null ?
如果把 b.destroy() 改为 b = null.
打印结果就是
dao.TestIsNull@126b249
null
哪位达人给解释一下???
public void destroy(){
this = null;//你要注意,实际上你的类是存在的。this根本就不能够被改变
//所以就算它能够编译通过,这句话根本就不会有任何作用
}
javac没办法编译,你是怎么通过的?
不过好像 jdk 自带的 javac 是不能编译, eclipse 不知道为什么可以,可能IBM认为这样可以,
算了,反正这句加上去也是白加。
估计eclipse并没有使用 jdk的 javac
我的jcreator也编译不了,不过jb8和其它开发工具可能使用其它的编译器,如jb8使用自己的jdk1.3,而我的jcreator使用的是jdk1.4