-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSimpGen.java
More file actions
48 lines (36 loc) · 953 Bytes
/
SimpGen.java
File metadata and controls
48 lines (36 loc) · 953 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
39
40
41
42
43
44
45
46
47
48
package chapter14;
class TwoGen<T, V> {
T ob1;
V ob2;
//Pass the constructor a reference to
//an object of type T and object of type V
TwoGen(T o1, V o2) {
ob1 = o1;
ob2 = o2;
}
//Show types of T and V
void showTypes() {
System.out.println("Type of T is " + ob1.getClass().getName());
System.out.println("Type of V is " + ob2.getClass().getName());
}
T getOb1() {
return ob1;
}
V getOb2() {
return ob2;
}
}
//Demonstrates TwoGen Class
class SimpGen {
public static void main(String[] args) {
TwoGen<Integer, String> obj
= new TwoGen<Integer, String>(88, "Generics");
//Show the types
obj.showTypes();
//Obtain and show values
int v = obj.getOb1();
System.out.println("value : " + v);
String str = obj.getOb2();
System.out.println("value : " + str);
}
}