<Swing Dev> 6179357: Generics: JList: getSelectedValues
Tom Hawtin
Thomas.Hawtin at Sun.COM
Mon Jan 19 15:00:36 UTC 2009
Alexander Potochkin wrote:
>
> but you can use the following workaround:
>
> @SuppressWarnings("unchecked")
> E[] array = (E[])new Object[10];
Consider this client code:
JList<String> list = ...;
String[] strs = list.getSelectedValues();
In that code you have a ClassCastException from Object[] to String[].
Unfortunately you can *not*, for obscure language reasons, even declare
JList<E>.getSelectedValues as:
public <T super E> T[] getSelectedValues()
So, I think if you want the method genericisted, it needs to be
deprecated (or as near as we are allowed) and replaced. Although for my
money, you're always better off going for a model and leaving the actual
JComponent well alone.
Tom Hawtin
More information about the swing-dev
mailing list