As he said in JVMS8 :
Although the Java virtual machine defines a boolean type, it provides only very limited support. The Java Virtual Machine instructions are not specifically dedicated to boolean operations. Instead of this expression in Java, a programming language that works with Boolean values ββis compiled to use data types of the Java virtual machine.
Indeed, these two methods:
boolean expr1(boolean a, boolean b) { return a || b; } int expr2(int a, int b) { return ((a != 0) || (b != 0)) ? 1 : 0; }
will produce the same byte code (except for the method signature)
boolean expr1(boolean, boolean); Signature: (ZZ)Z Code: 0: iload_1 1: ifne 8 4: iload_2 5: ifeq 12 8: iconst_1 9: goto 13 12: iconst_0 13: ireturn int expr2(int, int); Signature: (II)I Code: 0: iload_1 1: ifne 8 4: iload_2 5: ifeq 12 8: iconst_1 9: goto 13 12: iconst_0 13: ireturn
So, I do not understand why the JVM needs a boolean type yet? Just for checking the runtime of method signatures?
source share