I have declared the following method:
private void mockInvokeDBHandler(Map<String, Object>... rows) {
List<Map<String, Object>> allRows = Arrays.asList(rows));
// rest of method omitted
}
It is invoked by clients using something like
Map<String, Object> row1 = new HashMap<String, Object>();
Map<String, Object> row2 = new HashMap<String, Object>();
mockInvokeDBHandler(row1, row2);
However, the last line shown above generates a warning
Type safety : A generic array of Map is created for a varargs parameter
I don't fully understand this, but I guess it's because varargs params are converted to arrays, and it's a bad idea to have an array whose type is a generic class (because generics are invariant, whereas arrays aren't).
I could resolve this problem by redifining the method as
private void mockInvokeDBHandler(List<Map<String, Object>> rows) {
}
But this places the burden of putting the row objects into a List on the client, which I'd rather avoid. Is there a better solution?