-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerics.java
More file actions
59 lines (48 loc) · 1.15 KB
/
Copy pathGenerics.java
File metadata and controls
59 lines (48 loc) · 1.15 KB
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
49
50
51
52
53
54
55
56
57
58
59
package BASICS;
import java.util.ArrayList;
import java.util.Scanner;
class MyGeneric<T1,T2>{
int val;
private T1 t1;
private T2 t2;
public MyGeneric(int val, T1 t1, T2 t2){
this.t1 = t1;
this.val = val;
this.t2 = t2;
}
public T2 getT2() {
return t2;
}
public void setT2(T2 t2) {
this.t2 = t2;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
public T1 getT1() {
return t1;
}
public void setT1(T1 t1) {
this.t1 = t1;
}
}
public class Generics {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("Harhsit");
arrayList.add(223);
arrayList.add(21);
arrayList.add(new Scanner(System.in));
// var a = arrayList.get(3);
int a = (int)arrayList.get(2);
System.out.println(a);
MyGeneric<String, Character> g1 = new MyGeneric(22, "Harshit", 'V');
String s = g1.getT1();
System.out.println(s);
char ch = g1.getT2();
System.out.println(ch);
}
}