- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericsUse.java
More file actions
Latest commit
31 lines (30 loc) · 674 Bytes
/
Copy pathGenericsUse.java
File metadata and controls
31 lines (30 loc) · 674 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
classGeneric<O,P>{
Oob1;
Pob2;
publicGeneric(Oob1, Pob2){
this.ob1=ob1;
this.ob2=ob2;
}
publicvoidgetTypeofO(){
System.out.println("Type of First Object is " + ob1.getClass().getName());
}
publicvoidgetTypeofP(){
System.out.println("Type of Second Object is " + ob2.getClass().getName());
}
publicOgetObject(Oob1){
returnob1;
}
publicPgetObject(){
returnob2;
}
}
publicclassGenericsUse{
publicstaticvoidmain(String[] args){
Generic<String,Integer> g1=newGeneric<>("Akash",19);
g1.getTypeofO();
g1.getTypeofP();
Stringname=g1.getObject("Akash");
Integerage=g1.getObject();
System.out.println(name+" "+age);
}
}