-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMyGenPair.java
More file actions
38 lines (32 loc) · 774 Bytes
/
MyGenPair.java
File metadata and controls
38 lines (32 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package generics;
public class MyGenPair<K, V> {
private K key;
private V value;
public MyGenPair(K key, V value) {
this.key = key;
this.value = value;
}
public MyGenPair() {
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
public static void main(String[] args) {
MyGenPair<String, Integer> person = new MyGenPair<>();
person.key = "Nfo";
person.value = 32;
System.out.println(person.key);
System.out.println(person.value);
System.out.println(person.getKey());
System.out.println(person.getValue());
}
}
// type parameters naming convention
// T - Type
// E - Element
// K - Key
// N - Number
// V - Value