Community
Participate
Working Groups
Compile the source code below in Eclipse and run it. Do the same using Sun JDK (1.4.1 or 1.5). The results are different. The problem is connected with +' ': Eclipse treats it as ' ' but Sun JDK converts that space into 32 (+' ' => + (int) ' ' => +32 => 32) (which IMHO is correct). PS. I'm not sure if I picked the proper product (JDT)... The source code: public class CharIntTest { /** * Eclipse value: " " * JDK value: "32" */ public static String C = "" + +' '; /** * Eclipse value: "32" * JDK value: "32" */ public static String I = "" + +32; public static void main(String[] args) { System.out.println(C); System.out.println(I); } }
I will investigate.
This is a bug with the computation of a compile-time constant with an unary expression. If (+' ') is replaced with (' '), then the Eclipse compiler behaves well. I am not sure why +' ' would be treated as a char. I will check the JLS.
Created attachment 16176 [details] Apply on HEAD
We can also get rid of the operator parameter in the compute constant methods.
Created attachment 16177 [details] Apply on HEAD New patch. Apply on the jdt/core project.
Created attachment 16178 [details] Apply on jdt.core.test.compiler
Fixed and released in HEAD. Regression test added.
Verified (in I20041214-2000) that the provided test case has the following output when compiled with Eclipse: 32 32