mardi 1 mai 2018

Java reflection - check is assignable from classmetadata

ok - I am walking a resource tree looking for classes that extend a particular super class, possibly not directly - I have code that works, but I'm having to resolve a concrete class, and I'm just wondering whether the same thing is possible without actually resolving the class - here is my working function:

 private static <T> boolean checkInherits(Class<T> superClass, ClassMetadata classInformation)
{
    try
    {
        Class<?> theClass = Class.forName(classInformation.getClassName());
        return superClass.isAssignableFrom( theClass );
    }
    catch (Throwable theException)
    {
        return false;
    }
}

So - is it possible to do that without using class.forName()? ie straight from the class metadata?





Aucun commentaire:

Enregistrer un commentaire