• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding passing null into method parameter

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


How to know which gets invoked ?? I tried it out the string version does but how ? and also if we remove the string version the Integer Version gets invoked and removing that then the Object Version so how do we know which to choose?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I complied your code and it throws the error like "reference to method is ambiguous, both method method(String s) and method(Integer s)".

The rule is something like this:
The method which is nearest to the parameter is called first, means, the child class object is first checked, then its parent, and then its parent and so on..
e.g

If we comment out the "integer version", then it looks for parent class
e.g


HTH
 
Dhruv Arya
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot I got what you were trying to say.. Thanks alot !
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome I saw this type of questions many time here. Just search this forum with tags like "method calling sequence", "which method get invoked". etc
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually there is a important thing to remember. If you have overloaded methods with parameters in the same inheritance tree then the lowest level subclass will be invoked. If any other type is included then it will be ambiguous as both the types can accept the argument value.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote:If you have overloaded methods with parameters in the same inheritance tree then the lowest level subclass will be invoked.


I think, this is more technical version of what I want to say
 
reply
    Bookmark Topic Watch Topic
  • New Topic