Hello,
I have the following code, which generates a compiler error on the f(x) call:
import java.util.*;
class Test {
static <T extends Comparable<T>> void f( List<T> l ) {}
static <E extends List<? extends Comparable<?>>> E g( E x ) {
// <T>f(java.util.List<T>) in Test cannot be applied to (E)
f(x);
return x;
}
}
my f-method computes the next permutation of the list in-place.
Instead of a method g, I have a class that implements Iterator<E>.
When my iterator is constructed with an ArrayList<Integer>, I want the next()-method to return an ArrayList<Integer>, and the superclass List<Integer>
The Problem here seems to be, that the compiler can't infer that "?" should be "T".
I'm certain my attempt is way too complicated, all I want is to keep f() in the current form, as a generic helper method, and an iterator-class, that computes the permutations using f(), and returns them in the type of the original list.
Thanks for helping!