• 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

Is it safe to ignore return values?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic