I'm designign an argument of a method, for a class that has to handle generic enumerations (I mean, the class could be part of a library, and the user will provide that class method with a user-defined enumeration, whose specific type is not known to the class being designed - let's call this class the "library class").

I want to syntactically constrain that argument type as much as possible so that only correct types will be allowed.

My requirements are that the type must be an enumeration that implements a specific interface, `EnumKind`:

```
public interface EnumKind {

    String getText();

}

```

So far I have been able to write this type:

```
Class<? extends Enum<? extends EnumKind>> t;

```

With that declaration, and having these:

```
public enum MyEnumKind implements EnumKind {

    // ...

    public String getText() {
        // TODO Auto-generated method stub
        return null;
    }

}

public class MyClassKind implements EnumKind {

    @Override
    public String getText() {
        // TODO Auto-generated method stub
        return null;
    }

}

public enum MyEnum {

}

```

Only `t = MyEnumKind.class` is correct, other assignments (like `t = MyClassKind.class`) are rejected from the compiler, which is the behaviour I want.

Now, in the body of my method I can succesfully do:

```
Enum<? extends EnumKind>[] tt = t.getEnumConstants();

```

But I haven't found a way to directly retrieve the `EnumKind`s, to get access to each enumeration constant `getText()` method.

How do I get an array of `EnumKind` elements without explicit casting? Is that type declaration the best I can write, or can I improve it?  

If explicit casting can't be avoided, can I be 100% safe that the type declaration will avoid any possibility of any `ClassCastException` (or any similar exception) being thrown?

---

**EDIT**

---

I'll elaborate a bit more, since I'm hitting another road block.

The `EnumKind` interface requires the enumeration to associate a string to a each enum constant, i.e.:

```
public enum MyEnumKind implements EnumKind {

    A("#A#"),
    B("#B#"),
    C("#C#");

    private String text;

    private Token(String text) {
        this.text = text;
    }

    @Override
    public String getText() {
        return text;
    }

}

```

Next, I want to retrieve the enum constant that corresponds to a specific string, e.g.

```
? enumValue = getValueFor("#A#");

```

`enumValue` (what should be its type?) should represent `MyEnumKind.A` here, and there's no need to know the actual value, since `enumValue` will be passed to another method.

And I've designed my library class like this (after @JoopEggen answer):

```
public class EnumManager<T extends Enum<?> & EnumKind> {

    private Class<T> en;

    public EnumManager(Class<T> en) {
        this.en = en;
    }

   protected ? getValueFor(String s) {
        for(EnumKind ek : en.getEnumConstants()) {
            if(s.equals(ek.getText())) {
                // I found the enum constant I need... and now?
                return ? ;
            }
        }

    }

    //...

```

How should I complete that code?