I have decompiled a Java class which contain this line :
DatabaseError.throwSqlException((int)23);
Until now i believe that Java consider that literal numeric value is int, So why they cast 23 ? And in general how Java deal with hard coded numeric values ?
Edit: Im not interested in this specific case, but interested to go deeper with Java in general.
I still believe it is related to the used decompiler.
It can be assumed that the signature of the method is DatabaseError.throwSqlException(int i).
The statement DatabaseError.throwSqlException((int)23) would be compiled as DatabaseError.throwSqlException(23) - the literal is of type int and the method parameter type is of type int
the DatabaseError.throwSqlException((int)23L) would be compiled as DatabaseError.throwSqlException(23) - the value can be stored without precision lose in an int and the method parameter type is of type int
The byte code is in both cases
bipush 23 // push the value on the operand stack
invokestatic // DatabaseError.throwSqlException:(I)V
Decompiled it would be DatabaseError.throwSqlException(23). Because in case it was 23L in the source code, this information isn't in the bytecode.
A bytecode similar to DatabaseError.throwSqlException((int)23) could be
ldc2_w // push a long from constant pool on the operand stack
l2i // convert top value on the operand stack from long to int
invokestatic // DatabaseError.throwSqlException:(I)V
But this is decompiled by jad and jd-gui to DatabaseError.throwSqlException((int)23L) (notice the L after the value).
edit The above bytecode is decompiled by CFR as DatabaseError.throwSqlException((int)23). So it really depend on the used decompiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With