The method is public static void method(Object[] params)
, how should I call it in the following scenarios?
ClassA a
ClassA a
, ClassB b
, ClassC c
?
thank youYou can create the array of objects on the fly:
method(new Object[] { a, b, c});
Another suggestion is that you change the signature of the method so that it uses java varargs:
public static void method(Object... params)
Nice thing is that it is compiled into a method with the same signature as above (Object[] params)
. But it may be called like method(a)
or method(a, b, c)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With