简体   繁体   中英

Given a java.lang.reflect.Method object, is there an easy way to obtain a hierachry of the methods it overrides

Given a java.lang.reflect.Method object, is there an easy way to obtain a hierachry of the methods it overrides. For example:

class A {
    public void someMethod() { ... }
}

interface B {
    public void someMethod();
}

class C extends A {
    public void someMethod() { ... }
}

class D extends C implements B {
    public void someMethod() { ... }
}

Given the java.lang.reflect.Method object for D#someMethod, can I easily get the tree:

D#someMethod
 |
 +- C#someMethod
 |   |
 |   +- A#someMethod
 |
 +- B#someMethod

Am guessing there must be a simple way of doing this, perhaps an existing library?

Ultimately did not find a useful library, so as per assylias comment simply used reflection to traverse the inheritance and build a tree (including superclasses and interfaces). I didn't build a method tree but rather a class tree which can subsequently be 'walked'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM