If I change ?
to Object
code compiles.
Q1. Is there any way of changing unwind
method signature to be applicable for the <?> getList()
?
Q2. If not, have you heard any design principles about designing parametrized API with <?>
?
public class Main {
public static void main(String[] args) {
unwind(getList());
}
public static List<List<?>> getList() {
return new LinkedList<List<?>>();
}
public static<T> Collection<T> unwind(Collection<? extends Collection<T>> collection) {
return collection.iterator().next();
}
}
PS. I've stuck on dealing with collection of results of several call to Future<?> java.util.concurrent.ExecutorService.submit(Runnable task)
It would be much better for me to have Future<Object>
result of the method. Is there any issue with API design here?
> into a method that expects an argument of type Collection extends Collection> (calling "unwind(getList())"). The former is parametrized for a list of unknown type whereas the latter is a parametrized for a collection type T. With this structure, "unwind" method might end up returning a collection of unknown type. Is that what you want?
– gramonov Aug 23 '14 at 22:23