find all classes and interfaces a class extends or implements recursively

后端 未结 8 1216
孤独总比滥情好
孤独总比滥情好 2021-02-12 22:13

I was wondering if there was an easy way of determining the complete list of Types that a Java class extends or implements recursively?

for instance:

cla         


        
8条回答
  •  忘了有多久
    2021-02-12 22:26

    It's very easy, in case your class is Foo then your code will be like this,

    public void getClassDetails() {
    
        Class klass = Foo.class;
        Class superKlass = klass.getSuperClass();
        Class[] interfaces = klass.getInterfaces();
    }
    

提交回复
热议问题