From: dimakura on
On Feb 19, 7:10 pm, Andreas Leitgeb <a...(a)gamma.logic.tuwien.ac.at>
wrote:
> Chris Uppal <chris.up...(a)metagnostic.REMOVE-THIS.org> wrote:
> > dimakura wrote:
> >> but i can not find why i can not use
> >> // char c = '\u000a'
> >> is it because '\u000a' is equivivalent to \n and this type is comment
> >> is a single-line?
> > Yes, exactly right.
>
> And to test yourself, whether you've really understood,
> predict what the compiler will say to that:
>
> // char c = '\u000a//'
>
> // :-)


yes, i understand: new line begin with comment!
ok.

just to test myself:

it is not an error:

// \u000a

but error is

// \u000a something_else

where "something_else" is not spaces or something placed in correct
Java-style comment

From: Patricia Shanahan on
dimakura wrote:
> On Feb 19, 7:10 pm, Andreas Leitgeb <a...(a)gamma.logic.tuwien.ac.at>
> wrote:
>> Chris Uppal <chris.up...(a)metagnostic.REMOVE-THIS.org> wrote:
>>> dimakura wrote:
>>>> but i can not find why i can not use
>>>> // char c = '\u000a'
>>>> is it because '\u000a' is equivivalent to \n and this type is comment
>>>> is a single-line?
>>> Yes, exactly right.
>> And to test yourself, whether you've really understood,
>> predict what the compiler will say to that:
>>
>> // char c = '\u000a//'
>>
>> // :-)
>
>
> yes, i understand: new line begin with comment!
> ok.
>
> just to test myself:
>
> it is not an error:
>
> // \u000a
>
> but error is
>
> // \u000a something_else
>
> where "something_else" is not spaces or something placed in correct
> Java-style comment
>

It is not an error. It is two lines of code, and something_else is on
the second line, not part of the one line comment. In the following
valid program, ("Hello, world"); is neither spaces nor a Java-style comment.

public class HelloWorld{
public static void main(String[] args){
System.out.println // \u000a ("Hello, world");
}
}

Patricia
From: Gordon Beaton on
On 20 Feb 2007 01:22:55 -0800, dimakura wrote:
> but error is
>
> // \u000a something_else
>
> where "something_else" is not spaces or something placed in correct
> Java-style comment

Not just comments and whitespace. It's valid if something_else is
anything that can appear at the start of a line, including statements
or declarations, etc, in the context of the most recent non-comment
before this line, e.g.:

public class
// \u000a Foo {
}

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
From: Knute Johnson on
Gordon Beaton wrote:
>
> Read section 3.2 of the JLS, which describes translation of the input
> to the compiler. The unicode escape sequences are translated into
> their corresponding unicode characters, *then* the resulting sequence
> of characters is tokenized.
>
> So when you escape a line feed as you've done, you are essentially
> writing this (illegal) code:
>
>
> char c = '
> '
>
> i.e. the closing quote ends up on the following line.
>
> Similarly, commenting the line results in this invalid sequence:
>
> // char c = '
> '
>
> /gordon
>

Gordon:

char c = \u0027\u002a\u0027\u003b

Do you know why they would process the unicode prior to determining if
it was part of a comment or literal first? It does provide for some
great obfuscation. I'm really glad it wasn't me that ran across this, I
could have spent days trying to figure this one out :-).

--

Knute Johnson
email s/nospam/knute/
From: Chris Uppal on
Knute Johnson wrote:

> char c = \u0027\u002a\u0027\u003b
>
> Do you know why they would process the unicode prior to determining if
> it was part of a comment or literal first?

I presume the idea is to allow the use of Unicode characters in identifiers and
comments without making the source completely inaccessible to people using
non-Unicode editors. Also to allow for the case where the source has to be
manipulated by non-Unicode programs (source code control, and so on).

-- chris



First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Axis2 vs. multirefs
Next: MYFaces in tomcat 5.x