I am reflectively getting classes and their declared classes, and I want to pass them into a function that takes classes, but it has generics on it.
// classes to pass into function
ClassPath.from(MyParent.class.getClassLoader())
.getTopLevelClasses()
.forEach(classInfo -> {
// checks...
Class<?> clazz = classInfo.load();
for (Class<?> declaredClass : clazz.getDeclaredClasses()) {
genericFunction(clazz, declaredClass); // the problem
}
});
// the function to pass into
<E extends Extendable<? extends Parent<E>>> void genericFunction(Class<? extends Parent<E>> parentClass, Extendable<E> extendableClass);
// classes used in generic function
public class MyParent extends Parent<MyExtendable> {
protected class MyExtendable extends Extendable<MyParent> {
}
}
public abstract class Parent<E extends Extendable<? extends Parent<E>>> {
}
public abstract class Extendable<E extends Parent<? extends Extendable<E>>> {
}
The problem is that I have no idea how to cast or reflective run that genericFunction()
with the Class<?>
objects.
I can assume that the classes that ClassPath
finds are compatible (e.g: they all properly extend Parent
and Extendable
in inner classes.)
I can change my (likely) messy and overcomplicated generics on the function and classes.
Aucun commentaire:
Enregistrer un commentaire