• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.out

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..

Can anybody clear my doubt...what does System.out.println(t) will do on t.. if t is an object.

If it calls toString() method on that object, why im not getting null pointer exception when t is equal to null
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Who says it calls toString()?

System.out is a PrintStream, and if you look at the API documentation for the print(Object) method it says

"The string produced by the String.valueOf(Object) method is translated into bytes..."

And when you look at the API documentation for String's valueOf(Object) method it says

"Returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned."

So that's why.
 
Srinivas Tuta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you paul
 
reply
    Bookmark Topic Watch Topic
  • New Topic