Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need clarification on overloaded method?

 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if i call the above method using "test(null)", it is calling the method which takes String as a argument.

Can anybody explain me, how it is called?
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java calls the method with the 'narrowest' type that you pass as an argument. String is more specific than Object.



this prints
short
short
long
long
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should go into the FAQ if it hasn't already, as it seems to come up quite often.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:This should go into the FAQ if it hasn't already, as it seems to come up quite often.

Its already. http://faq.javaranch.com/java/ScjpFaq#mostSpecific
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic