[HD Pg 0, Sec. 5.2.2 - stringbuilder-api]
Posted: Sat Jan 11, 2020 2:18 am
About this point :
If you pass a null, the string "null" is appended to or inserted in the existing StringBuilder. No NullPointerException is thrown.
=============
Failed with "The method append(Object) is ambiguous for the type StringBuilder."
============
Then i tried this one .
=======================
And it printed: Hello null
======================
Is it because if i directly pass a null , it has no way of knowing what the type of object being passed is ?
If you pass a null, the string "null" is appended to or inserted in the existing StringBuilder. No NullPointerException is thrown.
=============
Code: Select all
StringBuilder str = new StringBuilder("Hello");
str.append(null);
============
Then i tried this one .
Code: Select all
String str1 = null;
StringBuilder str = new StringBuilder("Hello ");
str.append(str1);
System.out.println(str);
And it printed: Hello null
======================
Is it because if i directly pass a null , it has no way of knowing what the type of object being passed is ?