Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between byte code .<init>()V vs .<init>(Z)V

Tags:

java

bytecode

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

like image 803
saeediqbal Avatar asked Feb 06 '13 04:02

saeediqbal


2 Answers

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
like image 196
Mike Samuel Avatar answered Nov 08 '22 16:11

Mike Samuel


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 {
...
}
like image 28
Evgeniy Dorofeev Avatar answered Nov 08 '22 14:11

Evgeniy Dorofeev