So I just found a behaviour I didn´t expect and I´d like for someone to clarify it for me, because while there are a lot of questions on how to overload a varargs there are none that I found to address this issue specifically.
Having the next piece of code:
public foo(Object... bar) { ... }
public foo(List<Object> bar) { ... }
And then calling this foo
method as
List<Sting> myParam = initializeWithSomething();
foo(myParam);
The varargs foo
method is favoured, putting the list as the only element in the created array during the method execution. If Java usually chooses the most specefic of the possible overloads, how come this happens?