In the code:
public interface ProductInterface {
public List<ProductVO> getProductPricing(ProductVO product, ProductVO prodPackage, String... pricingTypes) throws ServiceException;
}
What does
String... pricingTypes
mean? What type of construct is this?
It is called varargs. It works for any type as long as it's the last argument in the signature.
Basically, any number of parameters are put into an array. This does not mean that it is equivalent to an array.
A method that looks like:
void foo(int bar, Socket baz...)
will have an array of Socket (in this example) called baz.
So, if we call foo(32, sSock.accept(), new Socket())
we'll find an array with two Socket objects.
Calling it as foo(32, mySocketArray)
will not work as the type is not configured to take an array. However, if the signature is a varargs of arrays you can pass one or more arrays and get a two-dimensional array. For example, void bar(int bar, PrintStream[] baz...)
can take multiple arrays of PrintStream and stick them into a single PrintStream[][]
.
Oddly enough, due to the fact that arrays are objects, Object... foo
can take any number of arrays.