Why this is not allowed?
error: incompatible types:
List<TextBook>
cannot be converted toList<Book>
process(textBooks);
import java.util.*;
class Book {}
class TextBook extends Book {}
public class Sample {
public static void process(List<Book> books) {}
public static void main(String[] args) {
List<Book> books = new ArrayList<>();
process(books);
System.out.println(“OK”)
List<TextBook> textBooks = new ArrayList<>();
process(textBooks); # what is the problem in this statement?
System.out.println(“OK”);
}
}