Author Topic:   I don't get it!
Java Nut
unregistered
posted May 02, 2000 07:33 AM           
From the before mentioned Java Quiz Pages

Why does this not compile

public class AQuestion
{
//char a = '\u000A';
}

And this does:

public class AQuestion
{
//char a = '\u0001';
}

Note that the code in question is commented out in both instances, but the compiler parses this code and checks syntax anyway! Anyone know why?

satya5
ranch hand
posted May 02, 2000 09:47 AM             

Java Nut:

While I donot know the exact reason for this
kind of behavior, (if this is holding up your
work , i hope you take this comment in a
lighter sense ),

you could work around the problem using

/* char a = '\u000A'; */

which works.

Regds.

- satya

Ajith Kallambella
ranch hand
posted May 02, 2000 09:51 AM             
For some reason the compiler is not liking the
char declaration within the // comments

If you change it to an int, or any other damn
thing, it works fine.

Gods must be crazy.

maha anna
bartender
posted May 02, 2000 05:04 PM             
Java Nut,
The compiler acts according to the Java lang spec.

From JLS
--------
Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (§3.3) and the linefeed becomes a LineTerminator in step 2 (§3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (§3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'.

Please refer to JLS especially this section

regds
maha anna.

|