• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

case little strange !

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was trying declaration of char primitives , and I noted something strange: if I comment this line of code :
like: //char mm = '\u'; I have always compilation error (illegal escape character) even the line of code is commenteted .I can repair that comment adding another escape inside character asignements .what do you think ?
------------------
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is trying to read the \ as a character. That is why you have to escape the escape character.

Interesting observation.

You'll notice that most people here at javaranch use their real names (or at least names that look real). Please re-register following the guidelines on the registration page (the guidelines you agreed to follow when you registered). More detail on http://www.javaranch.com/name.jsp

Also, I am moving this thread to Java in General (beginner) because it appears to have nothing to do with the Cattle Drive assignments.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very interesting. I get the same thing with the other comment type, i.e., /* char mm = '\u'; */ also generates a compile error.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a java program is compiles the first thing that happens is that it is parsed for unicode. Everything is parsed - EVEN the comments. Compiling happens afterwards. So the system sees \u' and tries to convert that to its equivalent character - and can't figure out what to do with it. Therefore the error.
This of course leaves the opportunity to do all SORTS of fun stuff to your fellow programmers.
Try putting a \u002f\u002f in front of a line of code .
This of course translates into // which happens BEFORE the compile so the line is commented out.
Or better yet in the middle of a comments like
\* This is a long comment about \u002a\u005c
System.out.println("This should not print but WILL"); \u005c\u002A */
The \u002a\u005c translates to */ and ends the comment so the println gets compiled. < evil grin >
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic