<Swing Dev> 6179357: Generics: JList: ListCellRenderer & prototypeCellValue
Florian Brunner
fbrunnerlist at gmx.ch
Sat Feb 21 18:30:09 UTC 2009
Hi,
I think adding generics to the ListCellRenderer could also be useful. The problem is that in JList
the same cell renderer is used for the items as for the prototypeCellValue - and the
prototypeCellValue doesn't necessarily have be of the same type as the items!
So I think we have 3 options:
1) Don't provide a generic cell renderer/ allow only Object as parameter for the cell renderer in
JList.
2) Add a second generic parameter. Eg. something like:
class JList <E, P super E>{ ... }
and use P for the prototypeCellValue property as well as for the cell renderer.
3) Require prototypeCellValue to be of type E. In the probably rare cases, where this is a problem
one can still specify a common base class of the items and the prototypeCellValue as the generic
parameter or use a raw type JList.
I think it would be a pity not to provide a generic cell renderer (1) and think 2) is inconvenient
and confusing, since in my experiences prototypeCellValue is only used rarely.
So I'm voting for 3). For which option do you vote? For which reason?
Note I also propose to use:
ListCellRenderer<? super E> cellRenderer
rather than
ListCellRenderer<E> cellRenderer
in JList. This would make it more flexible. Do you agree? (It's actually the first time, I think, I
use 'super' with generics myself, but I think this is a good use case of it. So any comments are
welcome. ;-) )
-Florian
More information about the swing-dev
mailing list