Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic