And? Extends E
This is Java's generic syntax. e indicates the classes currently used by generics? Extends e indicates the subclass of E or the implementation of E.
Why is it necessary? Syntax like extends e?
For example, the add method of list <number> numblist can naturally accept subclasses of number, including double or integer. Therefore, you only need to add (E) The add parameter, and do not need to add (? Extends E ).
This is because the addall method is required. addall (collection <? Exntends E>) in this interface, if addall (collection <E>) is used, list <double> is not accepted as the parameter, because according to the official statement, java generics are "invariant. A list <double> is not a list <number>. It is indeed a list <? Extends number>.
It is worth noting that arrays are different. A double [] is a number [].
Reference: http://stackoverflow.com/questions/2770264/what-is-the-difference-between-e-extends-number-and-number
This is Java's generic syntax. e indicates the classes currently used by generics? Extends e indicates the subclass of E or the implementation of E.
Why is it necessary? Syntax like extends e?
For example, the add method of list <number> numblist can naturally accept subclasses of number, including double or integer. Therefore, you only need to add (E) The add parameter, and do not need to add (? Extends E ).
This is because the addall method is required. addall (collection <? Exntends E>) in this interface, if addall (collection <E>) is used, list <double> is not accepted as the parameter, because according to the official statement, java generics are "invariant. A list <double> is not a list <number>. It is indeed a list <? Extends number>.
It is worth noting that arrays are different. A double [] is a number [].
Reference: http://stackoverflow.com/questions/2770264/what-is-the-difference-between-e-extends-number-and-number