Maybe I am overlooking something very easy and obvious…
I have a method interface which goes like
private void render(Collection<Object> rows);
Now, the objects I need to pass is an array (from an enum):
Module[] mods = Module.values();
widget.render(mods);
Of course this does not work, but why does this not work:
widget.render(Arrays.asList(mods))
It turns my array to a collection of Module, and Module is an object…
Try changing your method signature to:
This is is saying your method takes a
Collectionwith any type of element, whereas before it was saying theCollectionshould specifically haveObjectas its type parameter.Using a wildcard like this will place limitations on how you can use the
Collectionthat is passed into the method, especially in regard to modifying it. You might want to show us what yourrendermethod is doing if you want more detailed advice.This post is worth reading with respect to using wildcarded collections in Java: What is PECS (Producer Extends Consumer Super)?