blob: 2457a91559fa3a94f5caf6cd8ba40c1f13eab64e (
plain)
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
|
import java.util.*;
class TreasureChest<T> {
protected Set<T> contents;
public TreasureChest() {
contents = new HashSet<T>();
}
public void add(T o) {
contents.add(o);
}
}
public class SimpleGenericsProgram {
public static void main(String []argv) {
TreasureChest<String> tc1 = new TreasureChest<String>();
TreasureChest<Integer> tc2 = new TreasureChest<Integer>();
tc1.add("dubloon");
tc2.add(new Integer("777"));
}
}
|