Gabriel Petrovay Gabriel Petrovay -4 years ago 111
Java Question

How to indicate that a Class object should represent a subtype of an interface?

I have the following enum:

public enum NotifierTypes {

private final Class internalValue;

NotifierTypes(Class internalValue) {
this.internalValue = internalValue;

public Class getNotifierClass() {
return internalValue;

public interface INotifier {...}
public class EmailNotifier implements INotifier {...}

I want the arguments provided to the constructor to represent types that implement an interface, say
. How can I do that?

Answer Source

Use a generic bound:

private final Class<? extends INotifier> internalName;

NotifierTypes(Class<? extends INotifier> internalName){ /* ... */ }

public Class<? extends INotifier> getIntName(){ /* ... */ }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download