Why isn't List<Integer> a List<Number>? What is PECS?
Short answer
List<Integer> is not a List<Number>, even though Integer is a Number. For flexibility remember PECS: reading out uses extends, putting in uses super.
3 points to say:
- Read only:
List<? extends Number>. - Write only:
List<? super Integer>. - Read and write: use a concrete
List<T>.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.