• 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
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Literal Line feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When I compile the code below, I get an error message stating, "illegal line end in character literal" What is reason for that? When and how can we use this literal then?

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pal Sudarshan:
Hi,

When I compile the code below, I get an error message stating, "illegal line end in character literal" What is reason for that? When and how can we use this literal then?



During the compilation process, the unicode character \u000A gets converted to the end of line character which causes the compiler error. You can use '\n' for newline instead.
 
Pal Sudarshan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, thank you for the reply.

Why does it cause compiler error? "It gets converted to end of line." If it gets end of line, what is the problem with that? Why doesn't it do the same function as '\n'? If it is in the language, then where can we use the literal?

Again, thanks for the reply.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem with that code is the compiler converts unicode characters before it parses the code. Therefore, the java compiler will end up seeing a line that looks like:

char c = '
';

which is illegal. I don't know the exact sequence the compiler goes through, but I suppose you could use unicode sequences to build up keywords and that would also work.

In any case, the compiler does not convert '\n' before parsing the code, so use that instead of '\u000A'.

Robert
 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic