-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerics7.java
More file actions
38 lines (32 loc) · 926 Bytes
/
Generics7.java
File metadata and controls
38 lines (32 loc) · 926 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
/**
* Created by Admin on 18-04-2017.
*/
public class Generics7 {
public static class Stats<T extends Number>{
T[] t;
Stats(T[] t){
this.t=t;
}
public double getAvg(){
double avg=0;
for(int i=0;i<t.length;i++){
avg+=t[i].doubleValue();
}
return avg/t.length;
}
public boolean isAvgSame(Stats<?> t){
if(this.getAvg() == t.getAvg()){
return true;
}
return false;
}
}
public static void main(String[] args){
Integer[] arr={1, 4, 2, 5, 6};
Stats<Integer> stats=new Stats<>(arr);
Double[] arr2={1.0, 23.0, 5.1};
Stats<Double> stats2=new Stats<>(arr2);
System.out.println(stats.getAvg());
System.out.println(stats.isAvgSame(stats2));
}
}