public class IntSumWithWildcard
1: //IntSumWithWildcard.java
2: //Exactly the same as IntSumWithWildcard.java except that T in line 30
3: //has been replaced by the "wildcard character" '?'.
5: //Question being asked here:
6: //Is the "integer sum" of the values in the T array the same, no
7: //matter what kind of (numeric, of course) values are in the array?
8: public class IntSumWithWildcard<T extends Number>
9: {
10: private T[] values;
12: public IntSumWithWildcard(T[] a)
13: {
14: values = a;
15: }
17: //Return an integer sum in all cases.
18: public int intSum()
19: {
20: double sum = 0.0;
21: for (int i = 0; i < values.length; i++)
22: {
23: sum += values[i].doubleValue();
24: }
25: return (int) sum;
26: }
28: //Return an integer sum in all cases.
29: public boolean hasSameIntSum(IntSumWithWildcard<?> obj)
30: {
31: if (this.intSum() == obj.intSum()) //"this" is redundant here
32: {
33: return true;
34: }
35: return false;
36: }
37: }