java - 了解类文件 : 'putfield Test.a : int [12]'

标签 java eclipse class compilation

我在 eclipse 中打开了我的 java 类文件,我对这一行有疑问。

iconst_10
putfield Test.a : int [12]

[12] 是什么意思?它是否表示已分配字节数?

我的java代码是

class Test {
   public Integer a = 5;
   public static void main(String[] args) {
      Test t = new Test();
      t.a = 4;//This line compiles to the above code.
   }
}

这是 javap 代码,但与 eclipse 代码完全不同

public Test();
  Code:
   0:   aload_0
   1:   invokespecial   #10; //Method java/lang/Object."<init>":()V
   4:   aload_0
   5:   iconst_5
   6:   invokestatic    #12; //Method java/lang/Integer.valueOf:(I)Ljava/lang/In
teger;
   9:   putfield        #18; //Field a:Ljava/lang/Integer;
   12:  return

public static void main(java.lang.String[]);
  Code:
   0:   new     #1; //class Test
   3:   dup
   4:   invokespecial   #26; //Method "<init>":()V
   7:   astore_1
   8:   aload_1
   9:   iconst_4
   10:  invokestatic    #12; //Method java/lang/Integer.valueOf:(I)Ljava/lang/In
teger;
   13:  putfield        #18; //Field a:Ljava/lang/Integer;
   16:  return

}

最佳答案

它不是分配的字节。它很可能是字段 Test.a 的常量池中的索引。

关于java - 了解类文件 : 'putfield Test.a : int [12]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17941602/

相关文章:

python - 如何定义我只想在 __init__ 方法中使用的 Python 方法,即不能从类定义外部访问的方法?

java - 如何在 Java 中使用带值的终端参数?

java - 在 div、selenium java eclipse 中找不到输入元素

java - Tomcat7 在 ubuntu Eclipse Juno 中抛出异常

c++ - 如何从结构中调用静态类方法?

java - 有没有办法确定类在 Java 中是什么类型的实例?

java - 我可以更改方法返回变量的内容吗?

java - 为什么此代码有 "one off error"?

java - 在 Struts 1.x 中使用 java 设置 select 的默认值

eclipse - 如何在 Eclipse 中设置匿名书签?