This is the next question from previous questions about string initialization in Java.
After some small tests in Java, I came across the following question:
Why can I execute this statement
String concatenated = str2 + " a_literal_string";
when the str2 a String object is initialized to null ( String str2 = null; ), but I can not call the toString() method on str2 ? Then how does Java concatenate a null String object and a string literal ?
By the way, I also tried combining the zero-initialized Integer and the string literal "a_literal_string" , and I got the same thing as "null a_literal_string" in the console. So, whatever null type does the same thing?
PS: System.out.println(concatenated); gives null a_literal_string as console output.
java string null
Gab ζ― ε₯½δΊΊ
source share