The Artima Developer Community
Sponsored Link

Java Buzz Forum
Non-Static Method Calls Considered Harmful?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos Perez

Posts: 153
Nickname: ceperez
Registered: Jan, 2003

Carlos Perez is a Software Architect with over 10 years of industry experience
Non-Static Method Calls Considered Harmful? Posted: Jul 14, 2003 7:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Perez.
Original Post: Non-Static Method Calls Considered Harmful?
Feed Title: .:Manageability:.
Feed URL: http://www.manageability.org/blog/stuff/rssDisabled?portal_status_message=Syndication+is+Disabled
Feed Description: Random thoughts on the manageability of complex software.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Perez
Latest Posts From .:Manageability:.

Advertisement

Kasia and Simon are both recommending that .toString() never be called.  Rather, they recommend String.valueOf() to avoid the dreaded NullPointerException.  Well it's a pretty good tip especially within catch blocks.  However, extrapolating, should non-static method calls ever be used at all?

That's an extremely radical proposal and I don't think its going to fit well with many people.  However, here's a rule of thumb, wrappers of primitive types, strings or even value types should never be null.  They should always be their default value. 

Now you have a choice, either enforce this stringent requirement, or never call a method of a value type, always use an intermediary that checks for null. So two choices, pick your poison!

This incidentally has been discussed in the Tiger release in the context of autoboxing. The original choice was not to throw an exception when a primitive wrapper was null, rather than convert it to its default.  However, that would have masked too many errors and is semantically awkward, so the choice was to throw the NPE.

Read: Non-Static Method Calls Considered Harmful?

Topic: Java and the scripting world Previous Topic   Next Topic Topic: The Missing Future

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use