Search code examples
javaclassgenericsgeneric-collections

"> expected" error on creating a class with generics


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?


Solution

  • 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.