I have a (probably simple) question regarding genrics in Java. I have the following class:
public class ValueCollection<Y> implements Collection<Y>
{
private Set<Entry<?, Y>> entries;
public ValueCollection(Set<Entry<?, Y>> entries)
{
this.entries = entries;
}
...
}
When I call the constructor like this:
return new ValueCollection<V>(entries);
I get the following compiler error:
The constructor ValueCollection<V>(Set<Map.Entry<K,V>>) is undefined
If I change my class to this:
public class ValueCollection<X, Y> implements Collection<Y>
{
private Set<Entry<X, Y>> entries;
public ValueCollection(Set<Entry<X, Y>> entries)
{
this.entries = entries;
}
...
}
and my constructor call to this:
return new ValueCollection<K, V>(this.entries());
the compile error goes away. I'm just wondering why this is the case. Thanks for the help!
new ValueCollection<V>(entries)in the first case? Your first class only has one type parameter.