Community
Participate
Working Groups
Build: M5++ Compile the following with javac and run it with java (version 1.4.0-rc-b91) public class A { static final char NegThree= (char)-3; public static void main(String[] args) { System.out.println(-3 == NegThree); } } You will get false. Try this with Eclipse, and you will get true. This is wrong. It appears that the compiler is inlining the incorrect value, because if you remove the "final" modifier it runs correctly.
I think I find the problem. As both operands are constant, the compiler optimizes the code, it computes the result of the operation and just put this value in the byte code. But I think there is a typo in the code which manages that, in EqualExpression.computeConstant(TypeBinding, TypeBinding). With the following modification, the behavior of the generated code is correct. public final void computeConstant(TypeBinding leftTb, TypeBinding rightTb) { if ((left.constant != NotAConstant) && (right.constant != NotAConstant)) { constant = Constant.computeConstantOperationEQUAL_EQUAL( left.constant, leftTb.id, <============= there is the modification EQUAL_EQUAL, right.constant, rightTb.id); if (((bits & OperatorMASK) >> OperatorSHIFT) == NOT_EQUAL) constant = Constant.fromValue(!constant.booleanValue()); } else { constant = NotAConstant; } }
Good find. Thanks. Fixed.