aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Var-Args problem 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 "Var-Args problem" Watch "Var-Args problem" New topic
Author

Var-Args problem

garima jain
Ranch Hand

Joined: Sep 22, 2008
Posts: 60
Source: http://www.examlab.tk/ and Practice Exam: 2 Question No:33


If I uncomment the above commented lines, code does not compile. With comments, it compiles just fine. That goes to say that overloading is fine here. My question is whether there is any way to call any of these two methods successfully.
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
Garima,
Overloading, compilation wise, is fine here. But usage wise, its not fine. Because, at the end, you are unable to call these methods because of the ambiguity issue, as there is varargs in one call and the other is boxing+varargs...

One way of solving this issue would be to change the first callMethod to public static void callMethod(Integer i){ (removal of varargs syntax)...that way, you will get Primitive as the output.

Another option is to remove the varargs from the second call. Or else, in the parameters you are passing, do not pass variables that involve unboxing...

Solutions are many...But, with the same exact code you have given, I don't think you can call those methods.
garima jain
Ranch Hand

Joined: Sep 22, 2008
Posts: 60
Thanks Rekha...
Fabio Nascimento
Greenhorn

Joined: Nov 16, 2008
Posts: 16
I didnt know about that ambiguous error, what a tricky for the exam heh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Var-Args problem
 
Similar Threads
Inner Class Problem
overloading
Doubt related to var-args
How to construct a Class object to represent a primitive type?
Var-args and method overloading doubt