0

如果我们有这样的代码:

class A {
  private hash = 0;

  public void test(){
    if (hash == 1) {
    //dosomething
    }
  }
}

比较究竟在哪里进行?

以下是我的理解:

  1. 将哈希加载到线程的堆栈中,命名为 r1。
  2. 将 r1 与文字 1 进行比较。

这样对吗 ?在这个意义上,堆中的哈希可以改变吗?

4

1 回答 1

4

字段哈希和常量 1 都加载到堆栈上。然后进行比较:

 ...
 GETFIELD A.hash : I    // push hash onto the stack
 ICONST_1               // push 1 onto the stack
 IF_ICMPNE L1           // pop the top two ints off the stack and compare them 
 ...                    // do smth
 L1
 RETURN
于 2013-05-30T03:19:13.580 回答