Community
Participate
Working Groups
According to the JDT compiler the following source code is correct: public class Demo { Object ok = (Object) new Object(); Object nok = ((Object)) new Object(); } javac and javadoc both find the second cast expression in error. Demo.java:3: ';' expected Object nok = ((Object)) new Object() ^ 1 error Version of javac and javadoc java version "1.4.2_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03) Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode) In my opinion both type casts may be correct, because extra parantheses can be added to any expression, though I am not really sure. I read JDT's compliance settings as: code that compiles in JDT compiles in a 1.4 (or 1.3) JDK. This does not hold here. It might be a defect of Sun's javac implementation, relative to the JLS. The practical problem is not with the javac compatibility, because I use that compiler rarely, but with javadoc, which is called by the JDT and which uses the javac parser apparently.
This was an Eclipse compiler bug which got resolved in 3.0 stream.