//IntSumWithoutWildcard.java
//Will not compile with IntSumWithoutWildcardDemo.java because of the
//generic T parameter in line 30. Motivates the "wildcard".

//Question being asked here:
//Is the "integer sum" of the values in the T array the same, no
//matter what kind of (numeric, of course) values are in the array?
public class IntSumWithoutWildcard<T extends Number>
{
    private T[] values;

    public IntSumWithoutWildcard(T[] a)
    {
        values = a;
    }

    //Return an integer sum in all cases.
    public int intSum()
    {
        double sum = 0.0;
        for (int i = 0; i < values.length; i++)
        {
            sum += values[i].doubleValue();
        }
        return (int) sum;
    }

    //Return an integer sum in all cases.
    public boolean hasSameIntSum(IntSumWithoutWildcard<T> obj)
    {
        if (this.intSum() == obj.intSum()) //"this" is redundant here
        {
            return true;
        }
        return false;
    }
}
