The problem of Java generics is the same as the code in the book, but the result is different?

parent: Fruit
subclass: Apple

List < Fruit > fruitList = new ArrayList < Fruit > ();

fruitList.add (new Apple ()); is OK, but I don"t want Apple to fit in

so create a function

public static < T > void add (List < T > list,T item) {

    list.add(item);
}


result add (fruitList,new Apple ()); can still be put in

however, "java programming ideas" should not be put into

.

I"m confused. Has the mechanism in the book been removed?

Oct.19,2021

found the same question outside the wall. The author made a mistake here.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eabf36-47e6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eabf36-47e6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?