有没有选项可以为null?

时间:2012-11-20 11:02:36

标签: java

  

可能重复:
  Can “this” ever be null in Java?

我有线程代码:

  @Override
  public void run() {
    try {
      process();
    } finally {
      Factory.close(this);
    }
  }

this可以选择null吗?

3 个答案:

答案 0 :(得分:4)

is there option that this can be null

否。 this引用不能为null。它总是指向当前正在执行该代码的Thread实例。

答案 1 :(得分:0)

这里至少没有错。这在JAVA中永远不会为空。可能是你的问题在别的地方。尝试提交更多代码

答案 2 :(得分:0)

this在Java中不能nullnull表示它指向无对象,(它只是垃圾变量)。 this表示,在对象中,您现在正在实施,它应该指向自己。

相关问题