Answer by nagarjuna chimakurthi for How to do method overloading for null...
class Sample{ public static void main (String[] args) { Sample s = new Sample(); s.printVal(null); } public static void printVal(Object i){ System.out.println("obj called "+i); } public static void...
View ArticleAnswer by chitrendra chaudhary for How to do method overloading for null...
there is an ambiguity because of doSomething(char[] obj) and doSomething(Integer obj).char[] and Integer both are the same superior for null that's why they are ambiguous.
View ArticleAnswer by Jafar Ali for How to do method overloading for null argument?
I Have tried this and when there is exactly one pair of overloaded method and one of them has a parameter type Object then the compiler will always select the method with more specific type. But when...
View ArticleAnswer by Joachim Sauer for How to do method overloading for null argument?
Java will always try to use the most specific applicable version of a method that's available (see JLS §15.12.2).Object, char[] and Integer can all take null as a valid value. Therefore all 3 version...
View ArticleAnswer by Ankit for How to do method overloading for null argument?
Every class in Java extends Object class.Even Integer class also extends Object. Hence both Object and Integer are considered as Object instance. So when you pass null as a parameter than compiler gets...
View ArticleAnswer by jmg for How to do method overloading for null argument?
Each pair of these three methods is ambiguous by itself when called with a null argument. Because each parameter type is a reference type. The following are the three ways to call one specific method...
View ArticleAnswer by Lars Noschinski for How to do method overloading for null argument?
null is a valid value for any of the three types; so the compiler cannot decide which function to use. Use something like doSomething((Object)null) or doSomething((Integer)null) instead.
View ArticleHow to do method overloading for null argument?
I have added three methods with parameters:public static void doSomething(Object obj) { System.out.println("Object called");}public static void doSomething(char[] obj) { System.out.println("Array...
View Article
More Pages to Explore .....