i wanted to know how i can improve the current code or if there is a more effective/cleaner way to cast the AnnotatedElement return to a class type instead of making a method for every type ex asClass, asMethod, etc...
protected AnnotatedElement create() {
if (type == Type.CLASS) {
return new ClassFinder(name).get(); // Return Class
} else if (type == Type.CONSTRUCTOR) {
return new ConstructorFinder(name).get(); // Return Constructor
} else if (type == Type.METHOD) {
return new MethodFinder(name).get(); // Return Method
} else {
throw new IllegalStateException();
}
}
public Class<?> asClass() {
return (Class<?>) create();
}
public Constructor asConstructor() {
return (Constructor) create();
}
public Method asMethod() {
return (Method) create();
}
Aucun commentaire:
Enregistrer un commentaire