I declared the following method:
private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>> allRows = Arrays.asList(rows));
It is called 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
Security Type: creates a general Map array for the varargs parameter
I don’t quite understand this, but I think this is because the varargs parameters are converted to arrays, and it is a bad idea to have an array whose type is a common class (since generics are invariant and arrays are not).
I could solve this problem by reworking the method as
private void mockInvokeDBHandler(List<Map<String, Object>> rows) { }
But this puts the burden of putting string objects in a list on the client, which I would rather avoid. Is there a better solution?
java generics variadic-functions
Dónal
source share