You put because it is not there

S

Stefan Ram

Sometimes, it is surprising what error messages Java
implementations give:

Main.java:3: error: '.class' expected
{ if( true )int x; }}
^
Does the implementation really expects to see
»if( true )int .class« or »if( true ).class«?

The complete source code was:

public final class Main
{ public static void main( final java.lang.String[] args )
{ if( true )int x; }}

You also can get the error message text »'.class' expected«
with the following programs:

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( args.len[] ); }}

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( args.length[] ); }}

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( int ); }}

(The subject of this message is an automatic translation of
a German idiom that I wanted to use as a subject for this
post. The translation, however, does not express the sense
of the German idiom, nor does it have any sense at all.
However, it fits the topic of the contents, because it
demonstrates once again that automatic translation systems
have problems understanding what humans write, just as the
Java implementation does. The first error message should be
more like: »Statement expected.« [»int x;« is a block
statement, but not a statement.])
 
E

Eric Sosman

Sometimes, it is surprising what error messages Java
implementations give:

Main.java:3: error: '.class' expected
{ if( true )int x; }}
^
Does the implementation really expects to see
»if( true )int .class« or »if( true ).class«?

The former. That's what it said; why should you
disbelieve what it says about its own expectations? ;-)

Was its expectation reasonable? I think so, because
given the prefix `if ( true ) int' I can imagine no other
continuation than `. class' that could be part of a valid
parse, as in `if (true) int.class.getClassLoader();'.

Can you think of any other valid continuations?
 
K

Kevin McMurtrie

Sometimes, it is surprising what error messages Java
implementations give:

Main.java:3: error: '.class' expected
{ if( true )int x; }}
^
Does the implementation really expects to see
»if( true )int .class« or »if( true ).class«?

The complete source code was:

public final class Main
{ public static void main( final java.lang.String[] args )
{ if( true )int x; }}

Eclipse's suggestions turned that into:
if (true) assert int.class != null;

I didn't know primitives had a synthetic class field. I tried it and
found that int.class is a shortcut for Integer.TYPE.

You also can get the error message text »'.class' expected«
with the following programs:

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( args.len[] ); }}

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( args.length[] ); }}

public final class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println( int ); }}

(The subject of this message is an automatic translation of
a German idiom that I wanted to use as a subject for this
post. The translation, however, does not express the sense
of the German idiom, nor does it have any sense at all.
However, it fits the topic of the contents, because it
demonstrates once again that automatic translation systems
have problems understanding what humans write, just as the
Java implementation does. The first error message should be
more like: »Statement expected.« [»int x;« is a block
statement, but not a statement.])
 
A

Arved Sandstrom

Sometimes, it is surprising what error messages Java
implementations give:

Main.java:3: error: '.class' expected
{ if( true )int x; }}
^
Does the implementation really expects to see
»if( true )int .class« or »if( true ).class«?

The complete source code was:

public final class Main
{ public static void main( final java.lang.String[] args )
{ if( true )int x; }}

Eclipse's suggestions turned that into:
if (true) assert int.class != null;

I didn't know primitives had a synthetic class field. I tried it and
found that int.class is a shortcut for Integer.TYPE.
[ SNIP ]

FWIW I didn't know this either. I also had to quickly fire up a quick
test program to try it out. :) Learn something new every day.

AHS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top