-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfind_array.java
More file actions
58 lines (47 loc) · 1.22 KB
/
find_array.java
File metadata and controls
58 lines (47 loc) · 1.22 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
package com.company;
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.val = val;
this.t1 = t1;
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 cwh_110_generics {
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList();
// ArrayList<int> arrayList = new ArrayList(); -- this will produce an error
// arrayList.add("str1");
arrayList.add(54);
arrayList.add(643);
// arrayList.add(new Scanner(System.in));
int a = (int) arrayList.get(0);
// System.out.println(a);
MyGeneric<String, Integer> g1 = new MyGeneric(23, "MyString is my string ", 45);
String str = g1.getT1();
Integer int1 = g1.getT2();
System.out.println(str + int1);
}
}