Use math operators on generic variables in a generic Java class
问题 I'm trying to write some code that will allow me to perform basic math operations on a "T extends Number" object instance. It needs to be able to handle any number type that is a subclass of Number . I know some of the types under Number have .add() methods built in, and some even have .multiply() methods. I need to be able to multiply two generic variables of any possible type. I've searched and searched and haven't been able to come up with a clear answer of any kind. public class Circle<T