Few days ago, I made a typo in java code but it compiled and worked well. (though the result is strange.)
My code is:
public static void main(String args[]) {
String strOut;
char cSEP = '|';
String sSEP = "|";
strOut = "AA" + cSEP + "BB"; // Correct assignment
System.out.println(strOut); // The result is "AA|BB". This is OK.
strOut = "AA" + + cSEP + "BB"; // No Error : no token between two +
System.out.println(strOut); // The result is "AA124BB"
strOut = "AA" + + sSEP + "BB"; // This is compiler error !!!
System.out.println(strOut);
}
I cannot find why the 2nd assignment is not error and 124 is printed. (Of course, '|' is 124 in ASCII code. But why "124", not "|" ?)
Is this compiler bug? Or correct java syntax that I did not know yet ?