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:
private void render(Collection<?> rows);
This is is saying your method takes a Collection with any type of element, whereas before it was saying the Collection should specifically have Object as its type parameter.
Using a wildcard like this will place limitations on how you can use the Collection that is passed into the method, especially in regard to modifying it. You might want to show us what your render method 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)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With