On Dec 6, 2:05 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
kelvSYC <kelv...@gmail.com> writes:
private <T extends List<String> & RandomAccess> T
randomAccessStringList;
class Example
< T extends java.util.List< java.lang.String >& java.util.RandomAccess >
{ private T randomAccessStringList; }
Wouldn't that be genericizing the type?
Suppose you add a method
public setRandomAccessStringList(T list) { randomAccessStringList =
list; }
Then we have it that Example<ArrayList<String>> would accept setting
ArrayList<String> but not Vector<String>, while
Example<Vector<String>> would accept setting Vector<String> but not
ArrayList<String> - yet the original intention was for something that
could take both (and anything else that is both RandomAccess and
List<String>). It seems that there is still no way (short of raw
types) to have a T so that Example<T> takes ArrayList<String>,
Vector<String>, or MyCustomRandomAccessStringList as arguments.
So now working backwards: suppose we have
public <T extends List<String> & RandomAccess>
setRandomAccessSringList(T list) { randomAccessStringList = list; }
as a method in Example. How would you declare randomAccessStringList?