Incomplete java byte code

Hi, I have the following Java code,

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; } } 

but when I used the javap -c command to get the equivalent byte code, I get

  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 } 

I don't know about byte code here, because where are the declarations of the private variable and method?

Can someone explain this to me?

+4
source share
1 answer

You need the -p option to show private members:

 javap -c -p A 

Then you will see everything:

 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 } 
+12
source

Source: https://habr.com/ru/post/1480075/


All Articles