I am trying to write code that will allow me to perform basic mathematical operations on an instance of the "T extends Number" object. It should be able to handle any type of number that is a subclass of Number .
I know that some of the types under Number have built-in .add() methods, and some even have .multiply() methods. I need to be able to multiply two common variables of any possible type. I searched and searched and could not find a clear answer.
public class Circle<T extends Number> { private T center; private T radius; private T area;
Any help would be greatly appreciated. Generics are the hardest thing I've encountered while learning Java. I do not mind doing work on my feet, because I study better, so even a strong point in the right direction will be very useful.
java generics math
Will morton
source share