user2948795
user2948795

Reputation: 15

Collection of classes which implement a certain interface

I'm stuggling for some hours with this problem and I hope that you can help me out.

I have a interface which defines some methods:

public interface LanguageInterface {
         //...
}

There is a class which implement the LanguageInterface

public class ZPL implements LanguageInterface {
    // ...
}

And now I want to create an enum which contains all those classes.

public enum PrintingLanguage {
   ZPL(ZPL.class);

   private Class<LanguageInterface> clazz;

   PrintingLanguage(Class<LanguageInterface> clazz) {
      this.clazz = clazz;
}

And now I always get an eclipse which says

The constructor PrintingLanguage(Class< ZPL >) is undefined

I simply want to allow the constructor to accept only classes which implements this interface.

How can I make this work?

Thanks in advance!

Upvotes: 1

Views: 47

Answers (1)

SLaks
SLaks

Reputation: 887365

You want Class<? extends LanguageInterface>, to allow any type parameter that extends the interface.

Upvotes: 5

Related Questions