D
Darryl L. Pierce
Tor said:Why do you think so?
In my experience, such a situation would require a no-arg overloaded version
of the method.
Unless you don't like generalized examples and
have little experience with the situation yourself.
I have plenty of experience. My experience is that in a case where you need
to invoke a method knowing in advance that you're passing no object, you
should instead be invoking a method with no arguments. If you have 2
overloaded methods [foo(String) and foo(Object)] but need to invoke foo()
with the prior knowledge that you won't be passing an object, then the
proper design would include a foo() method, rather than casting null.
Or do you never
ever pass null as a parameter to a method?
Yes, I do. But, that has nothing to do with *casting* null to some type.
Are you perhaps opposed to
polymorphism and instead would call the methods fooObject() and
fooString() respectively?
Now you've moved past what I said into the area of strawman arguments.
A concrete example, then: JDialog's constructors with no parent, you
need to be explicit whether that's no parent Dialog or no parent
Frame.
Sun's not infallible. Though, it's not a case of Sun giving the wrong
constructors: it's the user's *use* of the constructor that's wrong, if the
user's instantiating JDialog with:
JDialog dialog = new JDialog((Frame )null,true);
rather than using:
JDialog dialog = new JDialog();
dialog.setModel(true);
Or maybe Sun *was* dumb for not supplying constructors such as:
JDialog(boolean modal);
JDialog(boolean model,String title);
JDialog(String title);
After all, if it's acceptable to *not* have a Frame or Dialog as a parent,
then it should be possible to construct the object *without* specifying
those objects, right?