Generics with 2-pars
Wed May 29 2024 19:29:59 GMT+0000 (Coordinated Universal Time)
Saved by
@exam123
public class Pair<K, V> {
private K key;
private V value;
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return this.key;
}
public V getValue() {
return this.value;
}
public static void main(String[] args) {
Pair<Integer, String> p1 = new Pair<>(123, "Generics");
Integer key = p1.getKey();
String value = p1.getValue();
System.out.println("Key: " + key);
System.out.println("Value: " + value);
}
}
content_copyCOPY
Comments