posted 10 years ago
Integer is indeed a subtype of Number, but that does not imply that List<Integer> is a subtype of List<Number>.
Instead of List<Number>, you could use a wildcard:
This means that nums is a list of some unknown, but definite type that extends Number. Note that you cannot add anything (except null) to such a list, because what that definite type is, is unknown (we know it's Integer because ints is a List<Integer>, but you can't know that by just looking at the type of the variable nums).