-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.java
33 lines (25 loc) · 887 Bytes
/
demo.java
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
/************************************************/
/* */
/* Compile: javac generic_programming/demo.java */
/* Run: java generic_programming.demo */
/* Note: Compile in sub_dir and run from root */
/* */
/************************************************/
package generic_programming;
class objs <T> {
T obj;
objs(T obj) {
this.obj = obj;
}
T getObject() {return obj;}
}
public class demo {
public static void main(String[] args) {
objs <String> sObj = new objs<String>("Hello World!");
System.out.println(sObj.getObject());
objs <Integer> iObj = new objs<Integer>(15);
System.out.println(iObj.getObject());
objs <Double> dObj = new objs<Double>(15.5);
System.out.println(dObj.getObject());
}
}