• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it safe to ignore return values?  RSS feed

 
Kerry Friesen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question for all you Java Ranchers.

Given the example:



Would it be safe to ignore the return value of putInt and just write the statement like this:



What would the impact to your program be (if any)?

Cheers,
Kerry

[ June 23, 2006: Message edited by: Kerry Friesen ]
[ June 23, 2006: Message edited by: Kerry Friesen ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is. The Javadoc specifically says that this method returns the same buffer object. Presumably the API is designed using the principle discussed by Clifton Craig here; you can chain multiple put() calls together, for notational convenience.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is "safe", but it is indicative of a poor design (always, not sometimes). This can be demonstrated with some very simple logic.

On a related note, the same can be said for signals (unfortunately referred to more often as exceptions). The dreaded fear of an empty catch block is precisely the same as ignoring a return value, however, the exception mechanism in Java contains some intrinsic flaws that are not identified in the community (I won't begin discussing them). This has led to the somewhat amusing 'checked vs unchecked exception' debate, which is quite entertaining from the sideline, especially when you can prove that it is never-ending
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!