In this piece of code, why the compiler is not able to reference the method that has varargs argument from static context.
private static void doSomething(int... nums) {
System.out.println("1");
}
private void doSomething(int num1, int num2) {
System.out.println("2");
}
public static void main(String[] args) {
doSomething(1,2);
}
JDK 17 is complaining Cannot make a static reference to the non-static method doSomething(int, int)
. Is this a bug or another feature I am not aware of.
JDK 8 and JDK 11 dont complain about it!