generic using 2 type parameter
Wed May 29 2024 09:16:02 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
public class Pair<K, V> {
private K key;
private V val;
public Pair(K key, V val) {
this.key = key;
this.val = val;
}
public K getKey() {
return this.key;
}
public V getVal() {
return this.val;
}
public static void main(String[] args) {
Pair<Integer, String> p1 = new Pair<>(123, "abc");
Integer i = p1.getKey();
System.out.println(i);
System.out.println(p1.getVal());
}
}
content_copyCOPY
Comments