-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericTest.java
More file actions
113 lines (99 loc) · 1.57 KB
/
Copy pathGenericTest.java
File metadata and controls
113 lines (99 loc) · 1.57 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
public class GenericTest {
public static void main(String[] args)
{
// IntValues iv = new IntValues(10, 20);
// iv.print();
// iv.swap();
// iv.print();
//
// System.out.println("------------------");
//
// FloatValues fv = new FloatValues(5.3f, 9.8f);
// fv.print();
// fv.swap();
// fv.print();
AnyValues<Integer> av = new AnyValues<Integer>(10, 20);
av.print();
av.swap();
av.print();
// AnyValues<Float> av2 = new AnyValues<Float>(10.2f, 52.5f);
// av2.print();
// av2.swap();
// av2.print();
}
}
//
//class IntValues
//{
// int x;
// int y;
//
//
// public IntValues(int x, int y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// void print()
// {
// System.out.println("x: "+x);
// System.out.println("y: "+y);
// }
//
// void swap()
// {
// int temp = x;
// x=y;
// y= temp;
// }
//}
//
//class FloatValues
//{
// float x;
// float y;
//
//
// public FloatValues(float x, float y) {
// super();
// this.x = x;
// this.y = y;
// }
//
// void print()
// {
// System.out.println("x: "+x);
// System.out.println("y: "+y);
// }
//
// void swap()
// {
// float temp = x;
// x=y;
// y= temp;
// }
//}
class AnyValues<T>
{
T x;
T y;
public AnyValues(T x, T y) {
super();
this.x = x;
this.y = y;
}
void print()
{
System.out.println("x: "+x);
System.out.println("y: "+y);
}
void swap()
{
T temp = x;
x=y;
y= temp;
int z = (int)x + (int)y;
System.out.println("uiyfdoiea "+z);
}
}