jeudi 11 mars 2021

Is it possible to get a list of class names those are implements a particular interface using Java Reflection?

For example:

interface Root<T> {
    public T getValue();
}

class A implements Root<String> {
    public String getValue() {
        return "";
    }
}

class B implements Root<Integer> {
    public int getValue() {
        return 0;
    }
}
  1. Is it possible to get a class details that are implemented Root interface via Java Reflection? I want the answer like this: [class A details, and class B details]
  2. In reflection, we can able to fetch method details via Method objects. Is it possible to identify a particular method is an interface method, ie: it is an override method but its signature is defined in that particular interface. For eg: I get Class B methods list, is it possible to identify getValue() is overridden method and its signature is defined in the Root interface?




Aucun commentaire:

Enregistrer un commentaire