Paul,

No it is not rhetorical. Most of the one-liners (and I don't necessarily agree with them either) at least have some perceived convenience value. In this case I see no value add at all. In fact unless you count on inlining then this adds pure overhead with the method call.

David

Paul Benedict said the following on 11/16/09 00:01:
David,

I think your question is mostly rhetorical. Most of the code in this
class are one-liners. If you can answer it for this method, you have
answered it for all.

I also think it's a common idiom... and so are the other small stuff in here.

Paul

On Sat, Nov 14, 2009 at 10:46 PM, David Holmes - Sun Microsystems
<david.hol...@sun.com> wrote:
Paul,

Paul Benedict said the following on 11/15/09 11:28:
I would like to propose adding this method:

/**
 * Selects the object if not {...@code null}; otherwise fallsback to the
 * specified default object.
 *
 * @param object the object to test
 * @param defaultObject the default object
 * @return the object if not {...@code null}; otherwise the default object
 */
public static Object defaultIfNull(Object object, Object defaultObject) {
   return (object != null) ? object : defaultObject;
}
I don't get it. Why would anyone need the above when they can write:

   obj != null ? obj : otherObj

themselves ??? Compared to

   defaultIfNull(obj, otherObj)

you don't even save any keystrokes (and this is with a static import)!

David Holmes


Reply via email to