File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A println() peculiarity...

 
Matthew Alesi
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Came across this problem writing a program for my Computer Science class. Reproduced here with simpler code:



All but the last call in main() work fine; the last throws a null pointer exception. What is the explanation for this seeming inconsistency?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3669
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are effectively passing 'null' in the first 3 calls. In the last call you are passing an object, whose toString() is returning a null.
The println method checks if the passed object is null (not whether the passed object's toString() returns null), in which case it prints "null" without trying to call any method on it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic