posted 9 months ago
Because that's how the library is implemented. The call is actually done from the String class: println(obj) calls String.valueOf(obj) which first checks for null. If the reference is null, the literal "null" will be returned, otherwise the object's toString() value is returned. This is why you should avoid calling String.valueOf() in your toString() implementations otherwise you could get into an endless recursion and blow the stack with a StackOverflowError.