package classes;class Box { class Inner { }}public class TestGetName { public static void main(String[] args) throws Exception { System.out.println("Box.class.getCanonicalName(): " + Box.class.getCanonicalName()); System.out.println("Box.class.getName(): " + Box.class.getName()); System.out.println("Box.class.getSimpleName(): " + Box.class.getSimpleName()); System.out.println("Box.Inner.class.getCanonicalName(): " + Box.Inner.class.getCanonicalName()); System.out.println("Box.Inner.class.getName(): " + Box.Inner.class.getName()); System.out.println("Box.Inner.class.getSimpleName(): " + Box.Inner.class.getSimpleName()); System.out.println("args.getClass().getCanonicalName(): " + args.getClass().getCanonicalName()); System.out.println("args.getClass().getName(): " + args.getClass().getName()); System.out.println("args.getClass().getSimpleName(): " + args.getClass().getSimpleName()); }}
输入结果如下:
Box.class.getCanonicalName(): classes.Box
Box.class.getName(): classes.BoxBox.class.getSimpleName(): BoxBox.Inner.class.getCanonicalName(): classes.Box.Inner
Box.Inner.class.getName(): classes.Box$InnerBox.Inner.class.getSimpleName(): Innerargs.getClass().getCanonicalName(): java.lang.String[]
args.getClass().getName(): [Ljava.lang.String;args.getClass().getSimpleName(): String[]