You can't add anythig to this list, because you don't know what type it really is.
Consider inheritance tree like this:
Number
|
|- BigInteger
|
|- NonNegativeInteger
|
|-PositiveInteger
You say that your list is list of elements which inherits from Number
. Ok, so suppose you want to add Number
to a list, but wait you could have List<BigInteger>
and you cannot put Number
into it.
Ok, so you could put BigInteger
, right? No! Because your list could be List<NonNegativeInteger>
. And the story goes on and on...
Declaring list as List<T extends SomeObject>
ensures you that when you get something from list it's of type SomeObject
. Nothing else is known.
So how to avoid the problem? Just remove the template.
List<Number>
And now you can put anything what inherites from Number
.
Or, what is even better in your case, change Double
to E
:
private <E extends Number> void AddOne(ArrayList<E> al, E num) {
al.add(num);
}