In this piece of code, why the compiler is not able to reference the method that has varargs argument from static context. 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! Answer
Tag: variadic-functions
Java two varargs in one method
Is there any way in Java to create a method, which is expecting two different varargs? I know, with the same object kind it isn’t possible because the compiler doesn’t know where to start or to end. But why it also isn’t possible with two different Object types? For example: Is there any way to create a method like this?
Varargs in method overloading in Java
The following code doesn’t compile. A compile-time error is issued. reference to test is ambiguous, both method test(int…) in varargspkg.Main and method test(float…) in varargspkg.Main match It seems to be obvious because the parameter values in the method call test(1, 2); can be promoted to int as well as float If anyone or both of the parameters are suffixed by