File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Advanced Overloading concepts in Java1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Advanced Overloading concepts in Java1.5" Watch "Advanced Overloading concepts in Java1.5" New topic
Author

Advanced Overloading concepts in Java1.5

ragavendran krishnamoothy
Greenhorn

Joined: Feb 13, 2007
Posts: 17
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

Joined: Mar 29, 2007
Posts: 115
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

Joined: Apr 12, 2007
Posts: 94
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!


debasmita
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advanced Overloading concepts in Java1.5