This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Var-Args problem

 
garima jain
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rekha...
 
Fabio Nascimento
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic