I am using reflection to call a method on a class that is dynamically constructed at runtime:
public String createJDBCProvider(Object[] args)
Here's how:
Method m = adminTask.getClass().getMethod("createJDBCProvider", Object[].class);
id = (String) m.invoke(adminTask, new Object[]{ "a", "b", "c" });
IDEA warns me that I'm guilty of redundant array creation for calling varargs method
.
The method I'm calling actually takes an Object[]
, not Object ...
but they're probably equivalent and interchangeable I think, so I forge ahead.
At runtime I get:
java.lang.IllegalArgumentException: wrong number of arguments
So it seems that, perhaps, my Object[]
is being passed as a sequence of Object
s. Is this what is happening? If so, how can I coerce it to not do so?
...
in the actual code is the most relevant part. Could you please show what's in your real code? – CursorialObject...
intoObject[]
. So yeah, they are equivalent. – Hardesty