In Java type arguments, does mean strictly subtypes only? or would E also suffice?
extends E means that it is also OK to add all members of a collection with elements of any type that is a subtype of E.
Type Parameter Naming Conventions The most commonly used type parameter names are: E - Element (used extensively by the Java Collections Framework) K - Key. N - Number.
In Java, Sis a subtype of T if S extends or implements T. Subtyping is transitive, meaning that if R is a subtype of S, then R is also a subtype of T (T is the super type of both Sand R). Here are some examples: - Integer is a subtype of Number. - ArrayList<E> is a subtype of Collection<E>
Whenever you want to restrict the type parameter to subtypes of a particular class you can use the bounded type parameter. If you just specify a type (class) as bounded parameter, only sub types of that particular class are accepted by the current generic class.
It's not strict; E
would suffice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With