Null and toString()
posted 11 years ago
Hi all,
I want to ask about the following code snippet
My question is ,in the first case,toString() is invoked implicitly on null,and it compiled and ran just fine,but then what is wrong with second line.
Bartender
posted 11 years ago
toString() is only called implicitly if the object passed isn’t null. If it is, the literal «null» is printed instead.
Bartender
posted 11 years ago
- 1
Sudhanshu Mishra wrote: Hi all,
I want to ask about the following code snippet
My question is ,in the first case,toString() is invoked implicitly on null,
No, it’s not. Somewhere down in one of the methods that println() calls, there’s code that’s something like
but then what is wrong with second line.
You’re dereferencing a null pointer.