You can rid yourself of the warning by returning a Number and not a T.
The warning is coming from this line:
return (T) sum;
You declare T as a subclass of Number, and *sum* is a variable of type Number. A superclass is not always able to be cast to a subclass. (i.e.
String is a subclass of Object, but you can't just cast any Object to a String). This code compiles without warning:
because any subclass can be referred to by a superclass reference.