Java Surprise 2: Another Example

While browsing through the micro testsuites of Java-front, I was remembered of another typical example:

int x = (int) ++y;
int x = (Integer) ++y;

The first statement is allowed. The second is not.

(See the first post on Java Surprise 2 for an explanation)

1 comment:

Martijn Vermaat said...

Of course, the 'fix' for this (will you ever encounter this in real code) is writing

int x = (Integer) (++y);

to make the parsing unambiguous.