Here's my code:
public class Sequence<T> {
protected List<T> sequence = new ArrayList<T>();
public Matrix<OrderedPair<T, ?>> createCartesianProduct(Sequence<?> secondSequence) {
Matrix<OrderedPair<T, ?>> result = new Matrix<OrderedPair<T, ?>>();
for (int rowIndex = 0; rowIndex < sequence.size(); rowIndex++) {
Sequence<OrderedPair<T, ?>> row = new Sequence<OrderedPair<T, ?>>();
for (int columnIndex = 0; columnIndex < secondSequence.length(); columnIndex++) {
row.add(new OrderedPair(sequence.get(rowIndex), secondSequence.sequence.get(columnIndex)));
}
}
return result;
}
}
This compiles in Eclipse, but on the line within the inner for loop ( row.add(...) ) I get the following three warnings:
OrderedPair
is a raw type. References to generic typeOrderedPair()<T1, T2>
should be parameterized.- Type Safety: The expression of type OrderedPair needs unchecked conversion to conform to
OrderedPair<T, ?>
- Type safety: The Constructor OrderedPair(Object, Object) belongs to the raw type OrderedPair. References to generic type OrderedPair
<T1, T2>
should be parameterized
I would like to use generics to enforce strong type-checking here, but I guess my understanding of generics is not sufficient to allow me to see how. Could someone educate me?
Thanks,
-- Ken