集册 Java实例教程 打印继承树

打印继承树

欢马劈雪     最近更新时间:2020-01-02 10:19:05

466
打印继承树
//from N o w J a v a . c o m - 时代Java

//package com.nowjava;


import static java.lang.System.out;


public class Main {

    public static void printInheritanceTree(Class<?> c) {

        out.format("Inheritance Tree => %n");

        Class<?> ancestor = c.getSuperclass();


        while (ancestor != null) {

            out.format("  %s%n", ancestor.getCanonicalName());

            ancestor = ancestor.getSuperclass();//来自 n  o  w  j  a  v  a . c o m

        }

        out.format("%n%n");

    }

}