well for me null+null is giving compile time error.
The operator + is undefined for the argument type(s) null, null
Joined: May 16, 2004
I dont have JDK1.3 but I checked up with 1.4. It does not compile. If there is indeed a discrepancy the importrant question is what is the correct behaviour from certification point of view? Ananda did you type in nul+null or null+null?
Jeroen Wenting's theory does not feel right. Any output from System.out should only happen after null+null (which does not compile). But one never knows. Did it compile for anyone else? [ May 20, 2004: Message edited by: Swamy Nathan ]
ananda s. roy
Joined: May 13, 2004
compiles & run without error or warning both on jdk 1.3.x and 1.4.x. . still
hello, whit a string that work but whit a primitive doesnt,if we try this, we get a complier error: System.out.println(null+ null+1);
Congratulation Barry in you post number 2500!
Joined: Aug 03, 2002
The "overloaded" string concatentation operator is defined to work when one operand is a reference to a String and the other is either a primitive, a reference to a String, or a reference to an object. The object reference can be null, in which case the string "null" will be used.
So "" + null, and null + "" are both OK, and result in a String "null". null + null should not work because not one of the operands is a reference to a String. The compiler can now detect this case and gives a compilation error.