How to pass an object array as a parameter in Java
•
Java
This method is public static void method (object [] params)). Should I call it under the following circumstances?
>One object as parameter classA a > multiple objects as parameter classA a, ClassB, ClassC? thank you
Solution
You can create an 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)
Well, it is compiled into the same signed method (object [] params)) as above But it can be called method (a) or method (a, c)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码