How to get the name of a class without the package?

后端 未结 3 560
余生分开走
余生分开走 2020-12-12 14:23

In C# we have Type.FullName and Type.Name for getting the name of a type (class in this case) with or without the namespace (package in java-world)

3条回答
  •  春和景丽
    2020-12-12 14:53

    If using a StackTraceElement, use:

    String fullClassName = stackTraceElement.getClassName();
    String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
    
    System.out.println(simpleClassName);
    

提交回复
热议问题