• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

overloading

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


please explain this problem?
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the problem is that you did not tell the problem.
So please let us execute a getter method on you to retrieve the problem statement. In short, what problem are you facing?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that he is facing an ambiguity compilation error because the compiler does not know which of the methods to invoke.

At runtime, var-args turn into an array, in your case int[] and Integer[]. The compiler could promote your invocation argument into both Integer[] and int[], hence does not know what to choose.

If you used new int[] {SOME VALUE} or new Integer[] {SOME_VALUE}, it would work.
 
vineet walia
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himanshu Kansal wrote:Well, the problem is that you did not tell the problem.
So please let us execute a getter method on you to retrieve the problem statement. In short, what problem are you facing?



are yaar complietime error kyu de raha ha ye ?
int wala rum hona chy what i think?
 
vineet walia
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:The problem is that he is facing an ambiguity compilation error because the compiler does not know which of the methods to invoke.

At runtime, var-args turn into an array, in your case int[] and Integer[]. The compiler could promote your invocation argument into both Integer[] and int[], hence does not know what to choose.

If you used new int[] {SOME VALUE} or new Integer[] {SOME_VALUE}, it would work.




thanks Sebastian Janisch
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hehe! okay. Sebastian answered it already.

it is just a matter of conversions and matching. If it is between Integer and int, the compiler matches the nearest. But arrays being objects confuse it, as it is to be resolved at compile time itself. If you give it a specific array of Integers or ints, it'll be easy as Sebastian said.
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vineet walia wrote:

Himanshu Kansal wrote:Well, the problem is that you did not tell the problem.
So please let us execute a getter method on you to retrieve the problem statement. In short, what problem are you facing?



are yaar complietime error kyu de raha ha ye ? (But buddy why is it giving a compilation error)
int wala rum hona chy what i think? (the int version should run I think)



vineet please Quote Your Sources when you post a question.

Also why are you writing in Hindi, not everyone understands Hindi, in the future try to write in English...
 
reply
    Bookmark Topic Watch Topic
  • New Topic