Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloading

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


please explain this problem?
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • 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: 138
  • Mark post as helpful
  • send pies
  • 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: 138
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic