• Post Reply Bookmark Topic Watch Topic
  • New Topic

variable-length arguments ambiguities  RSS feed

 
M Berg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi experts,

my class has a method "test" overloaded few times.
The compiler favours method with double type variable-length arguments (d) over int type (c).
It seems that the simplest possible variable-length call with int types is ambiguous...confusing.
Is there some basic or general rule around why this happens?
Or is this just a variable-length method specialty?



Many thanks again,
Kind regards MB
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would advise you to read this topic. Just let us know if you still don't get it after that.
 
M Berg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks I missed that one. Found this rule 4b:

4. Combination of the following overloaded methods will result in compiler error:
a. Var-args (V) of primitive type same as argument primitive type
b. Widening + Var-args (WV)
c. Boxing/Unboxing + Var-args (BV)


But just what part of my code exactly breaks or violetes this rule 4b: is it 1) my overloaded methods or 2) my method calls?!
The compiler says only my method call is ambiguous, actual methods seem fine for compiler.

Many thanks
Kind regards MB
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method calls make it ambiguous. Ambiguous just means that the compiler doesn't know which method to call because multiple methods match the signature.
If you change your method call to this it works:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!