Multiple Type Parameters : Generic Parameters « Generics « Java Tutorial






class Pair<KeyType, ValueType> {
  // Constructor
  public Pair(KeyType aKey, ValueType aValue) {
    key = aKey;
    value = aValue;
  }

  // Get the key for this pair
  public KeyType getKey() {
    return key;
  }

  // Get the value for this pair
  public ValueType getValue() {
    return value;
  }

  // Set the value for this pair
  public void setValue(ValueType aValue) {
    value = aValue;
  }

  private KeyType key;

  private ValueType value;
}

public class MainClass {

  public static void main(String[] a) {
    Pair<Integer, String> p = new Pair<Integer, String>(1, "A");

    System.out.println(p.getKey().getClass().getName());
  }
}
java.lang.Integer








12.4.Generic Parameters
12.4.1.Using the ? wildcard
12.4.2.Using Bounded Wildcards in Methods
12.4.3.Multiple Type Parameters
12.4.4.Type Parameter Bounds
12.4.5.Constraints on a Wildcard