public class IntSumWithWildcardDemo
1: //IntSumWithWildcardDemo.java
2: //Exactly the same as IntSumWithoutWildcardDemo.java, except for the name.
3: //And this time every thing compiles!
5: public class IntSumWithWildcardDemo
6: {
7: public static void main(String args[])
8: {
9: System.out.println();
11: Integer intNums[] =
12: {
13: 1, 2, 3, 4, 5 //autoboxing
14: };
15: IntSumWithWildcard<Integer> intObject
16: = new IntSumWithWildcard<>(intNums);
17: int iSum = intObject.intSum();
18: System.out.println("intObject sum is " + iSum);
20: Double doubleNums[] =
21: {
22: 1.1, 2.2, 3.3, 4.4, 5.5 //autoboxing
23: };
24: IntSumWithWildcard<Double> doubleObject
25: = new IntSumWithWildcard<>(doubleNums);
26: iSum = doubleObject.intSum();
27: System.out.println("doubleObject sum is " + iSum);
29: Float floatNums[] =
30: {
31: 1.1f, 2.2f, 3.3f, 4.4f, 5.5f
32: };
33: IntSumWithWildcard<Float> floatObject
34: = new IntSumWithWildcard<>(floatNums);
35: iSum = floatObject.intSum();
36: System.out.println("floatObject sum is " + iSum);
38: System.out.println();
40: System.out.print("The sums of intObject and doubleObject are ");
41: System.out.println
42: (
43: intObject.hasSameIntSum(doubleObject) ? "the same." : "different."
44: );
45: System.out.print("The sums of intObject and floatObject are ");
46: System.out.println
47: (
48: intObject.hasSameIntSum(floatObject) ? "the same." : "different."
49: );
50: System.out.print("The sums of doubleObject and floatObject are ");
51: System.out.println
52: (
53: doubleObject.hasSameIntSum(floatObject) ? "the same." : "different."
54: );
55: }
56: }