aspose file tools
The moose likes Beginning Java and the fly likes Why call to method with null invokes String Parameter and not Object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why call to method with null invokes String Parameter and not Object" Watch "Why call to method with null invokes String Parameter and not Object" New topic
Author

Why call to method with null invokes String Parameter and not Object

Sunny Kumar Kalra
Greenhorn

Joined: Oct 10, 2010
Posts: 15
Hi All,

I have a question in mind :

anyObject.callme(NULL)

callme (String)
callme (Object)

--> invokes callme(String ) and not callme(Object) , Why so ?
Michael Petrovich
Greenhorn

Joined: Sep 06, 2011
Posts: 16

The informal intuition is that one method is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.


In your case you can invoke callme (Object) both with new Object() and new String() parameters without Compile Time Errors. But you can't invoke callme (String) with new Object() without Compile Time Error so the callme (String) is more specific.
For more academic details see http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.12.2.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why call to method with null invokes String Parameter and not Object
 
Similar Threads
Ambiguous method
overloading doubt
Synchronized block doubt
Another Simple Query
Pls explain the program