2
  class k{
  public static void main(String[] args) {
   //('\u000d'); 
   }
}

In class k after main i have commented out line number 3 but still getting error unclosed character literal ,what could be the reason for it?

saurabh kumar
  • 155
  • 5
  • 26

3 Answers3

12

Unicode characters are parsed very early in the Java compilation, anyway \u000d isn't a valid character.

// The other style comments work.
/*('\u000d'); */

Edit

\u000d is converted into a newline, which ends your comment...

//('\u000d');

gets converted into

    //('
') // <-- bare line with ')

which isn't a valid character constant.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
4

It appears that '\u000d' is a newline character. The compiler sees the single line of code as two lines:

//('
');

This is why you get the error. The second line has an opening single-quote, but no closing one to match.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
3

It's a character literal. \u000d means "newline". While being in a commented line may seem to you like nothing in it is handled, this happens:

original : {
  //('\u000d');
}

pre-compile : {
  //('
'); // <- This is syntax error!!!
}
Unihedron
  • 10,902
  • 13
  • 62
  • 72