Generics limitation, or lack of skillz ?
Posted
by Two Shoes
on Stack Overflow
See other posts from Stack Overflow
or by Two Shoes
Published on 2010-06-10T17:05:35Z
Indexed on
2010/06/10
17:12 UTC
Read the original article
Hit count: 219
I want to define the following class as such:
public class CollectionAttribute<E extends Collection<T>> {
private String name;
private E value;
public CollectionAttribute(String name, E value) {
this.name = name;
this.value = value;
}
public E getValue() { return value; }
public void addValue(T value) { value.add(T); }
}
This won't compile (cannot resolve symbol T). If I replace the class declaration with the following:
public class CollectionAttribute<E extends Collection<?>>
Then I can't reference the parametrized type of the collection. Am I missing something or have I reached a limitation with generics in Java ?
© Stack Overflow or respective owner