Answer the question
In order to leave comments, you need to log in
Is the supertype metacharacter sentence in the textbook correct?
Hello!
Quote from the textbook (English and Russian version, Thinking in Java):
The argument apples is a List of some type that is the base type of Apple; thus you know that it is safe to add an Apple or a subtype of Apple.
The apples argument is a List container for some type that is Apple's base type; it follows that Apple and Apple-derived types can be safely included in a container.
public class SuperTypeWildcards {
static void writeTo(List<? super Apple> apples) {
apples.add(new Apple());
apples.add(new Jonathan());
// apples.add(new Fruit()); // Error
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question