• 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

Advanced Overloading concepts in Java1.5

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help in understanding the concept of having the Widening & Boxing & Var_Arg combination in overloaded methods....

Especially Widening along with Boxing ......
there is some order in which compiler will process in this case ...
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no detailed essay on the matter, but have a look at

https://coderanch.com/t/262293/java-programmer-SCJP/certification/re-ambiguous-method-calls

and the reply from keith lynn, it made things much clearer for me.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I checked the link. Its really informative.
The question posted by eisa was not clarified though.
here is the question:
class test {
public static void main(String[] args) {
test inst_test = new test();
inst_test.method ( 1 , 1 , 1);
inst_test.method( new Integer(1) , new Integer(2) , new Integer(3) );
inst_test.method ( 1 , new Integer(5) );
inst_test.method ( new Integer(10) , 1 );
}
public void method( Integer... I ){
System.out.println("Eye in the sky");
}
public void method( float... i ){//LINE 1
System.out.println("Fly in the pie");
}}

her doubt was, even when applying the rules of advanced overloading this code is not compiling.

I thought of giving the explaination to this to check my understanding :
In LINE 1 we are using primitive types i.e float.
So it follows the normal overloading concept.I mean that int will be compatible to float and that is why the second method will be called.
But when we use Wrapper class Float, the compatibility is lost and hence the result:" THE CODE COMPILES FINE"
Please help me in my understanding. Am I correct in giving this explaination?
thanks!
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic