Reputation: 3407
I am creating a class with Generics
public class MyEntry<K,Set<V extends SpecificEntry>> extends TimerTask{
//
}
But this is generating an error > expected As I see, the diamond operator is closed properly
If I make it
public class MyEntry<K,Set> extends TimerTask{
//
}
It works, but I want the second argument to be a set of a specific type.
What should be done to get this right?
Upvotes: 1
Views: 614
Reputation: 12440
A possible solution is not to use parameter for the Set
generic type, but instead parameterize just the element type of the Set:
public class MyEntry<K, V extends SpecificEntry> extends TimerTask{
//
}
and then use Set<V>
where needed.
Upvotes: 0
Reputation: 393781
If you want the second generic parameter to be a Set of a given type you need:
public class MyEntry<K,V extends Set<? extends SpecificEntry>> extends TimerTask
BTW, public class MyEntry<K,Set> extends TimerTask
doesn't work the way you think. Set
in your case is the name of the second generic type parameter, and has no relation to java.util.Set
.
Upvotes: 2