So, 2 votes for option 3), which is a reasonable one, I think. Pavel? Anyone else?
-Florian Am Sonntag, 22. Februar 2009 schrieb Erik Lundqvist: > Hi, > ListCellRenderer should absolutely be generic which rules out option 1 :) > I cannot remember ever using the prototypeCellValue so a bit worried about > saying too much about how people are using it, but it does not seem > unreasonable that it should be of the same type so I would go for Option 3 > as well which seems the simpler and most common use case. > > //erik > > 2009/2/21 Florian Brunner <fbrunnerl...@gmx.ch> > > > 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