mardi 1 juin 2021

Check if interface is extending another interface in Java using reflection

How to check reflectively in Java if interface extends another interface? I tried this:

  for (Class<?> aClass : classes) {
            int modifier = aClass.getModifiers();
            if (Modifier.isInterface(modifier)) {
                if (aClass.getSuperclass() != null && aClass.getSuperclass().equals(TopWorker.class)) {
                    log.info(aClass.getSimpleName() + " extends abstract  " + TopWorker.class.getSimpleName());
                }
            }
        }

Check for Superclass is not working (interface is not a class) Thanks





Aucun commentaire:

Enregistrer un commentaire