While programmers can use method overloading and array passing to accomplish much of what is accomplished with "varargs," or variable-length argument lists, using an ellipsis in a method's parameter list is more concise.
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Pepe Pepes wrote:Hi,
could you please explain why the following code:
results in "1" ?
When I remove the //1 line the result is "2".
Why doesn't a compiler report ambiguous methods ?
Thanks
Henry Wong wrote:
Fixed arity takes precedence over variable arity. And with fixed, one method is a perfect match (one parameter with an int array) and the other one doesn't match (two parameters of int array).
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Fixed arity takes precedence over variable arity. And with fixed, one method is a perfect match (one parameter with an int array) and the other one doesn't match (two parameters of int array).
Pepe Pepes wrote:
Fixed arity takes precedence over variable arity. And with fixed, one method is a perfect match (one parameter with an int array) and the other one doesn't match (two parameters of int array).
Could you please explain why you refer to the variable arity methods as fixed arity methods?
As I understand, the compiler see fun(int[] x) and fun(int[] x, int[] y) instead of theirs variable arity versions... Am I right ?
Thanks
Pepe Pepes wrote:Hi,
could you please explain why the following code:
results in "1" ?
When I remove the //1 line the result is "2".
Why doesn't a compiler report ambiguous methods ?
Thanks
Pepe Pepes wrote:Hi,
I've tried the following code:
The result is '1', so it seems that the compiler prefers method in which the list of parameters in a byte code matches to the list of arguments.
In this case the list of arguments is int[] and the list of parameters from the 1'st method is int[] and from the 2'nd method is int[][], so the first method is more specific.
Please correct me If I'm wrong.
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|