Java: How to define a collection of Enums that implements an interface

Viewed 577

I want to create a class with two simple methods - the first registers a type that needs to be processed. The second will process all the types that have been registered. The problem I've got is that the classes I want to register/process have certain limits - they must be Enums that implement and interface

I can't quite work out how to define the collection that will be used to store the registered types. A simplified version of my code is:

public class Example {
    interface MyType {
        // Add methods here
    }

    private List<what-goes-here?> store = new ArrayList<>();


    public <T extends Enum<?> & MyType> void registerType(@Nonnull Class<T> type) {
        store.add(type);
    }


    public void processAll() {
        for (T t : store) {         // Where do I define T?
            // process t
        }
    }
}
1 Answers
Related