-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut34.java
More file actions
41 lines (34 loc) · 832 Bytes
/
Tut34.java
File metadata and controls
41 lines (34 loc) · 832 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
package tutorial;
//Generics in java
//creating generics class
class GenExample<T,U>{
public T o;
public U s;
public GenExample(T o,U s) {
this.o=o;
this.s=s;
}
public T getName() {
return o;
}
public U getid() {
return s;
}
}
public class Tut34 {
public static void main(String[] args) {
GenExample<String,String> gn=new GenExample<String, String>("prathamessh", "STJCEM");
System.out.println(gn.getid());
System.out.println(gn.getName());
GenExample<Integer,Integer> gn1=new GenExample<Integer,Integer>(2,3);
System.out.println(gn1.getid());
System.out.println(gn1.getName());
System.out.println(printing("Prathamesh"));
printing(12323);
}
//creating generics method
public static <T> T printing(T name) {
System.out.println(name.getClass().getName()+" "+name);
return name;
}
}