To answer this question, we need to understand how the java compiler works in the case of Char
during lexical analysis.
Ideally, the compiler expects Char
to have only one character so that it looks at the opening '
and its end.
In the above case, it throws an error, since the analyser
indicates an error, indicating that: it has detected more than one character, which leads to the results of the "Unclosed Character literal"
, which, unfortunately, occurs before the compiler really checks the casting exception
or Type incompatibity
.
Poor IDE
do not know about everything that happens behind the scenes, give it more priority.
You can get all the errors at your disposal by changing '
to "
:
char a=true;//Line 1 char b=null; //Line 2 char c='\n'; //Line 3 char d="Hell"; //Line 4
As it is now in the above state, Lex
happy and moving forward.
source share