I\'ve read Oracle\'s expressions tutorial and couldn\'t understand this.
It is well known that the following line of code is valid Java syntax:
new O
Line containing only
new Object();
or to be more precise
new SomeClass();
is acceptable, because code of SomeClass()
constructor may be all we want.
But in case of lines containing only
"foo";
or
2;//or (2+3);
compiler knows that beside creating/reusing String literal or integer literal this code doesn't do anything else, which means it is probably some kind of programmer mistake so compiler can't accept it.