Overload Resolution Widening Boxing Varargs
One call site with long, Integer, and int... overloads shows resolution order: widening beats boxing beats varargs, so pick(1) lands on long.
Code
public class OverloadOrder {
static String pick(long value) {
return "pick(long) chosen";
}
static String pick(Integer value) {
return "pick(Integer) chosen";
}
static String pick(int... values) {
return "pick(int...) chosen";
}
public static void main(String[] args) {
int one = 1;
// resolution order: exact type, then widening, then boxing, then varargs
System.out.println("pick(1) -> " + pick(one));
System.out.println("pick(1L) -> " + pick(1L));
System.out.println("pick(7) -> " + pick(Integer.valueOf(7)));
System.out.println("pick(1,2) -> " + pick(1, 2));
System.out.println("pick() -> " + pick());
}
}Walking through the code — Overload Resolution Widening Boxing Varargs
Structurally, expect the class OverloadOrder and the functions pick and main and nothing else.
Points of care
- Prerequisite check: a working language toolchain, and that is the whole list.
Applying it
Signature: static String pick(long value)
The run emits 5 labeled sections — pick(1) ->, pick(1L) ->, pick(7) ->, pick(1,2) ->, pick() -> — one per step.
main is the driver: it invokes pick before returning.
Statements that matter
return "pick(Integer) chosen";
return "pick(int...) chosen";
return "pick(long) chosen";
Interactive Tools for This Topic
FAQ
- What does Overload Resolution Widening Boxing Varargs print when run?
- Invoke the file as-is — the `pick(1) ->`, `pick(1L) ->`, `pick(7) ->` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.