不完整的java字节码

时间:2013-05-10 09:00:44

标签: java bytecode

您好我有以下java代码,

public class A{
private String B="test_string";
private int AA;
public int C;
private int method1()
{
    int a;
    a=0;
    return a;
}


private int method1(int c, String d)
{
    int a;
    a=c;
    return a;
}
}

但是当我用javap -c命令得到我得到的等效字节码时,

    Compiled from "A.java"
public class A extends java.lang.Object{
public int C;

public A();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   aload_0
   5:   ldc #2; //String test_string
   7:   putfield    #3; //Field B:Ljava/lang/String;
   10:  return

}

我不清楚这里的字节代码,因为私有变量和方法声明在哪里?

任何人都可以向我解释这个吗?

1 个答案:

答案 0 :(得分:12)

您需要-p选项来显示私人成员:

javap -c -p A

然后你会看到一切:

Compiled from "A.java"
public class A {
  private java.lang.String B;

  private int AA;

  public int C;

  public A();
    Code:
       0: aload_0       
       1: invokespecial #1        // Method java/lang/Object."<init>":()V
       4: aload_0       
       5: ldc           #2        // String test_string
       7: putfield      #3        // Field B:Ljava/lang/String;
      10: return        

  private int method1();
    Code:
       0: iconst_0      
       1: istore_1      
       2: iload_1       
       3: ireturn       

  private int method1(int, java.lang.String);
    Code:
       0: iload_1       
       1: istore_3      
       2: iload_3       
       3: ireturn       
}