Pair.java
// TODO: Modify this generic class so that both elements have the same type.
public class Pair<T, S>
{
private T first;
private S second;
public Pair(T firstElement, S secondElement)
{
first = firstElement;
second = secondElement;
}
public T getFirst() { return first; }
public S getSecond() { return second; }
}
Use the following file:
PairTester.java
public class PairTester
{
public static void main(String[] args)
{
Pair<Integer> p = new Pair<Integer>(17, 19);
System.out.println(p.getFirst());
System.out.println("Expected: 17");
System.out.println(p.getSecond());
System.out.println("Expected: 19");
}
}