This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
OK, you get that error when there are two different methods that match the call, and the compiler has no rule to determine the priority.
The key point here are:
- 1 is an int. This can automatically be converted to a float. It can't be autoboxed to a Character.
- 'a' is a char, which is an integer type. Which means it can be autoboxed to a Character, but it can also be converted to a float.
This means that line 10 can match test(float, Character...), but it can't match test(Character...), because 1 can't match Character. So there's no ambiguity.
However, line 11 can match both. At this point the compiler checks its rules for prioritising. These can get a bit complicated (read the Java Language Specification for the full rules), but it turns out that none of them can be applied in this case. So the compiler doesn't know what to do, and you get the error.
Matthew Brown wrote:OK, you get that error when there are two different methods that match the call, and the compiler has no rule to determine the priority.
The key point here are:
- 1 is an int. This can automatically be converted to a float. It can't be autoboxed to a Character.
- 'a' is a char, which is an integer type. Which means it can be autoboxed to a Character, but it can also be converted to a float.
This means that line 10 can match test(float, Character...), but it can't match test(Character...), because 1 can't match Character. So there's no ambiguity.
However, line 11 can match both. At this point the compiler checks its rules for prioritising. These can get a bit complicated (read the Java Language Specification for the full rules), but it turns out that none of them can be applied in this case. So the compiler doesn't know what to do, and you get the error.