Would you please help me to make this work. I modified one of the
K&B exam question as follows:
code:
import java.util.*;
class BackLister {
public static <T> List<? super T> backwards(List<T> input)
{
List<T> output = new LinkedList<T>();
for (T t : input)
output.add(0, t);
return output;
}
}
public class TGeneric96 {
public static void main(
String[] args) {
BackLister bl = new BackLister();
List<Integer> ln = new ArrayList();
ln.add (1);
ln.add(2);
ln.add(3);
List<Number> lo = bl.backwards (ln);
System.out.println (lo);
}
}
At Line 19, there is compile error as follows:
TGeneric96.java:19: incompatible types
found : java.util.List<capture of ? super java.lang.Integer>
required: java.util.List<java.lang.Number>
List<Number> lo = bl.backwards (ln);
^
/code