This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages 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