Class AdapterView<T extends android.widget.Adapter>
requires that the concrete type used to create its instance extends Adapter and thus Adapter methods can be used inside.
Interface declaration (which actually doesn't have to be inside this class) accepts parameter AdapterView<?>
where ?
is so called wildcard. It means that type is unknown and can be anything.
For class it makes difference because its implementation will actually do something with type that is passed as generic parameter. You can define upper or lower bound on the type, but can't use unknown type in this case.
In case of interface - it is not a generic itself. Also, it's method is not generic, but accepts AdapterView
of any type. Because of the wildcard any AdapterView
can be passed to onItemLongClick
.
This is because AdapterView<A>
is not a subclass of AdapterView<B>
, even if A
is a subclass of B
.
It is explained here (with example):
https://docs.oracle.com/javase/tutorial/java/generics/subtyping.html
You may want to read more about Java generics here:
How do generics of generics work?
or/and here:
https://docs.oracle.com/javase/tutorial/java/generics/index.html