Hi, I have a problem when invoking overloaded constructors when I pass null as a parameter. This is my code:
When I call isString() it returns false. My question now is: what are the rules to invoke an overloaded constructor and what is the impact on this for the null value? [ May 22, 2003: Message edited by: Cindy Glass ]
Joined: Aug 20, 2001
Hi, Dirk, and Welcome to JavaRanch. In general, answer to your question lies in the fact that null is considered to be a very specific value, and when faced with overloaded methods, the most specific one will be called. (My examples below are methods, but I believe that the same holds true for constructors) That is, if you had:
and called aMethod(null), it would print "Integer" since that is the most specific method. However, if you also had
and called aMethod(null), you would get a compile-time error, since the compiler cannot tell what you class you mean for null to be (Integer and String are of equal specific-ness). You would have to cast your null, i.e., aMethod((String)null). However, when I try to compile you code, I get the following errors:
Of course this is because byte and char are not Strings in Java. [ May 22, 2003: Message edited by: Joel McNary ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.