I've this simple interface:
public interface Transportable<T> { public T getTransport(); } and a lot of classes that provide implementation, ie:
class A implements Transportable<ATransport> { public ATransport getTransport() { ATransport at=new ATransport(); [...] return at; } } class B implements Transportable<BTransport> { public BTransport getTransport() { BTransport bt=new BTransport(); [...] return bt; } } also I've lists of transportables objects, like this:
LinkedList<A> aList=new LinkedList<>(); and I want to call the getTransport method for all elements in aList, obtaining a LinkedList, doing something like that:
LinkedList<ATransport> atList = getTransport(aList); LinkedList<BTransport> btList = getTransport(bList); I don't want to write a foreach for every class I have, is there a way to implement this using generics? like:
public <T> List<???> getTransport(List<T> list) or something similar? I've tried but without luck, I think I'm missing something about generics and about the difference between using or etc...
Thank you!
public static <U, T extends Transportable<U>> List<U> getTransport(List<T> list)