Using Swing's ComboBoxModel
, type casting is required when getting the selected element, as the interface is defined as follows:
public interface ComboBoxModel<E> extends ListModel<E> {
void setSelectedItem(Object anItem);
Object getSelectedItem();
}
I would think the return type of getSelectedItem
could be E
.
In fact, this is done by the ListModel
interface the ComboBoxModel
inherits from, for selecting by index:
public interface ListModel<E> {
E getElementAt(int index);
}
What would be the reason to not use the E
type parameter in ComboBoxModel
?