Q:

Generic class that can take any numbers OR anything else that can be added

Title must be confusing, let me explain: Im writing a polynomial and so far it only works with double coefficients.
My idea is to make this class a generic one, where the user can specify the type of the coefficients, for example Polynomial<Double>. Now the coefficients cant be objects from any class, as they must have addition, subtraction, ... methods.
To solve this I made an Arithmetic interface with the necessary methods (add, subtract, multiply, divide) and now its Polynomial<? extends Arithmetic>.
But since Double does not implement this interface, of course, the user cant use Polynomial anymore.
My question in the end is: How can I make Polynomial generic in a way that the user can pass a subclass of java.lang.Number (or at least Double) OR my Arithmetic interface? If it cant be done, what should I do?

A:

One way would be to define a Polynomial<T> interface that has no restrictions on T whatsoever.
Then do an implementation of ArithmeticPolynomial implements Polynomial<Arithmetic>.
Then you can do another implementation for Number types, which just re-uses ArithmeticPolynomial, like this: NumberPolynomial<T extends Number> implements Polynomial<T>. This will use a wrapper/adapter class NumberArithmetic. Which wraps (adapts) a Number to Arithmetic.
If I understood you correctly, that would do it.

