Spring Batch's ItemWriter interface is this:
write(List<? extends T> items);
I'd like the ItemWriter to call a Service but my service has this:
process(List<T> items);
AFAIK, Java Generics are strict about casting types within collections.
List<? extends Foo> list1 = ...
List<Foo> list2 = Collections.unmodifiableList(list1);
Reason why list2
has to be read-only view of list1
is nicely explained in an answer of Generics : List is same as List?
Just go ahead and cast it. For reading, List<? extends Foo>
is certainly a List<Foo>
, the cast is absolutely safe. You can wrap it with Collections.unmodifiableList()
if you are paranoid.
List<? extends Foo> foos1 = ...;
@SuppressWarnings("unchecked")
List<Foo> foos2 = (List<Foo>)(List<?>)foos1;
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