<? extends Object>
is ALMOST useless. All that means is you're working with something that is not a primitive type. <? extends T>
means you're working with an object that is of type T
or a subclass of T
and has whatever methods and fields T
has.
<? extends T>
is useful to declare what an Object is expected to contain. It limits the scope of the container or the method which adds funcionality to the method/container.
For Example:
public class foobination<T extends foo>
{
private <? extends T> foo;
public foobination(T foo)
{
this.foo = foo;
}
public getFoo() { return foo; }
public void myFoobinator(<? extends T> foob)
{
foo.bash("foobinator was here");
foo.setBang(foob.getBang());
}
}
the other common use case would be: List<? extends T>
Where you're storing a collection of something and you don't know exactly what it is but you do know they will all be a subclass of whatever T is. That way you at least have some idea of what to expect to get back out of the collection.