getSelectedItem()
is a method of AdapterView
which return Adapter#getItem()
.
So the question is "Why the interface Adapter is not generic ?".
The answer is simply because an Android widget AdapterView can be used to store objects of different type. The purpose of the Adapter is to provide a consistent view of these objects.
If you add a generic parameter to the interface Adapter
(and AdapterView
, and Spinner
), you are fixing the type of the underlying data collection wich goes against the whole adapter thing.
The idea is that the adapter view doesn't need to be aware of the underlying data behind the adapter, thus it should'nt need to constrain its data type.
You can however specialize the Adapter
interface with a specific type (or a generic argment) in your own SpinnerAdapter
implementation and then access the data via the Adapter and not the AdapterView :
yourAdapter.getItem(spinner.getSelectedItemPosition()).