• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Advanced Overloading concepts in Java1.5

 
ragavendran krishnamoothy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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 ...
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no detailed essay on the matter, but have a look at

http://www.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.
 
debasmita pattnayak
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic