Class<? extends Something>
Here's my interpretation, it's class template but the class ? means the name of the class is undetermined and it extends the Something class.
if there's something wrong with my interpretation, let me know.
The extends keyword extends a class (indicates that a class is inherited from another class). In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class.
A class — in the context of Java — is a template used to create objects and to define object data types and methods. Classes are categories, and objects are items within each category. All class objects should have the basic class properties.
super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .
super E> , it means "something in the super direction" as opposed to something in the extends direction.
There are a few confusing answers here so I will try and clear this up. You define a generic as such:
public class Foo<T> { private T t; public void setValue(T t) { this.t = t; } public T getValue() { return t; } }
If you want a generic on Foo to always extend a class Bar you would declare it as such:
public class Foo<T extends Bar> { private T t; public void setValue(T t) { this.t = t; } public T getValue() { return t; } }
The ?
is used when you declare a variable.
Foo<? extends Bar>foo = getFoo();
OR
DoSomething(List<? extends Bar> listOfBarObjects) { //internals }
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