Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java type arguments, does <? extends E> mean strictly subtypes only? or would E also suffice?

In Java type arguments, does mean strictly subtypes only? or would E also suffice?

like image 391
Aaron Fi Avatar asked Jun 28 '10 22:06

Aaron Fi


People also ask

What does <? Extends E mean in Java?

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.

What data type is E in Java?

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.

What is subtype in Java with example?

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>

How do you restrict the types used as type arguments in generic classes and methods?

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.


1 Answers

It's not strict; E would suffice.

like image 176
Matt McHenry Avatar answered Sep 23 '22 06:09

Matt McHenry