Difference between byte code .()V vs .

2020-06-16 03:46发布

When I observe my Java project byte code, I see the following byte code :

java.lang.Object.()V

java.lang.Boolean.(Z)V

What is the meaning of <init>()V and <init>(Z)V

标签: java bytecode
2条回答
ゆ 、 Hurt°
2楼-- · 2020-06-16 04:18

It's all method signatures in bytecode used by JVM.

<init>()V and <init>(Z)V are construtor signatures. For JVM constructors are just as any other methods, they have a name, which is always <init>), and a return value, which is always V (means void). In our case Z means boolean parameter (B is reserved for byte)

that is

<init>(Z)V

in class Test's bytecode means

class Test {

    Test(boolean arg0) {
    }
}

you can also meet

 static <clinit>()V

which means static initialization block

static {
...
}
查看更多
三岁会撩人
3楼-- · 2020-06-16 04:28
java.lang.Object.()V

is a void method (V) on java.lang.Object that takes no arguments.

java.lang.Boolean.(Z)V

is a void method on java.lang.Boolean that takes a single boolean (Z since B is byte) argument.

In short,

 abc.def.WXYZ(IIIIIIIIIIIIII)J
 ^            ^              ^ 
 target_class argument-types return_type

See JNI Type Signatures for more detail.

The JNI uses the Java VM’s representation of type signatures. Table 3-2 shows these type signatures.

Table 3-2 Java VM Type Signatures

Type Signature             Java Type
Z                          boolean
B                          byte
...
L fully-qualified-class ;  fully-qualified-class
[ type                      type[]
( arg-types ) ret-type      method type

For example, the Java method:

long f (int n, String s, int[] arr); 

has the following type signature:

(ILjava/lang/String;[I)J
查看更多
登录 后发表回答