This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sunny Kumar Kalra
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Eclipse IDE Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic