0

I'm trying to create annotations that are only allowed on certain classes that implement an interface.

Currently, I'm trying to do this to use the Reflections library and loop over all classes with the annotation. This results in a Set<Class<?>>. Since I use generics in the Initializer class, I cannot check if each element in the set is an instance of that type, because instanceOf doesn't work with generics.

public abstract class Initializer<T> {
    private final JavaPlugin plugin;
    private final Set<Class<T>> classSet;

    public Initializer(JavaPlugin plugin, Reflections reflections, Class<? extends Annotation> annotation) {
        this.plugin = plugin;
        // Here I get an error because the required type is Set<Class<T>> and the provided Set<Class<?>>
        this.classSet = reflections.getTypesAnnotatedWith(annotation);
    }

    public JavaPlugin getPlugin() {
        return this.plugin;
    }
}

0 Answers0