java - Why does ComboBoxModel<E> return Object instead of E -


this question has answer here:

using swing's comboboxmodel, type casting required when getting selected element, interface defined follows:

public interface comboboxmodel<e> extends listmodel<e> {      void setselecteditem(object anitem);      object getselecteditem();  } 

i think return type of getselecteditem e. in fact, done listmodel interface comboboxmodel inherits from, selecting index:

public interface listmodel<e> {     e getelementat(int index);  } 

what reason not use e type parameter in comboboxmodel?

because combobox textfield may editable user.

jcombobox.seteditable(true); 

if combobox editable user may enter text combobox textfield returned string jcombobox.getselecteditem() no matter type parameter provided model.

if want object of e use:

  e e = jcombobox.getmodel().getelementat(jcombobox.getselectedindex()); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -