My question here is, why the doX(long...x) is not called for
doX(short,short)
If I change doX(long...x) for doX(long,long) it's called. (And it's nice according to rules I've learned
)
And if I delete the doX of the integers and Numbers it is also called.
And thinking about this I have another question.
In general if I have
m(A a1,A a2,A a3)
and m(A ...a)
and I call with m(a,a,a) the first is selected, isn't it? The rule is that if there multiple alternatives the novarargs wins?
A lot of thanks in advance,
The question is:
Given:
class Eggs {
int doX(Long x, Long y) { return 1; }
int doX(long... x) { return 2; }
int doX(Integer x, Integer y) { return 3; }
int doX(Number n, Number m) { return 4; }
public static void main(String[] args) {
new Eggs().go();
}
void go() {
short s = 7;
System.out.print(doX(s,s) + " ");
System.out.println(doX(7,7));
}
}
What is the result?
A). 1 1
B). 2 1
C). 3 1
D). 4 1
E). 1 3
F). 2 3
G). 3 3
H). 4 3
CORRECT: H
Question copyrighted Kathy sierra & Bert Bates