I am creating a class that, at present, stores lists of various types in an internal object called genericTable
. Each list (composed of either Double
, or Long
) are all held in an object which is an instance of class GenericList
.
Question: Why doesn't the method addVector
work?
The error under the red underline says the constructor Test<V>.GenericList<V>(List<List<V>>) is undefined
.
If I was working in a main
method (but had the same GenericList
class) and created genericTable
within the main method (using List<GenericList<?>> Table = new ArrayList<GenericList<?>>();
) and did genericTable.add(new GenericList<Long>(Arrays.asList(genericVector)));
(where genericVector
in this case is a List<Long>
), it works perfectly.
public class Test<V> {
private final List<GenericList<?>> genericTable = new ArrayList<GenericList<?>>();
public void addVector(List<V> genericVector) {
genericTable.add(new GenericList<V>(Arrays.asList(genericVector)));
}
private class GenericList<K> {
private final List<K> listGeneric;
public GenericList(List<K> input) {
listGeneric = input;
}
}
}