Java Class Simple Name Get simpleClassName(Class clazz)

Here you can find the source of simpleClassName(Class clazz)

Description

Generates a simplified name from a Class .

License

Apache License

Declaration

public static String simpleClassName(Class<?> clazz) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  w ww. ja  v  a  2s  .c o m
     * The shortcut to {@link #simpleClassName(Class)
     * simpleClassName(o.getClass())}.
     */
    public static String simpleClassName(Object o) {
        if (o == null) {
            return "null_object";
        } else {
            return simpleClassName(o.getClass());
        }
    }

    /**
     * Generates a simplified name from a {@link Class}. Similar to
     * {@link Class#getSimpleName()}, but it works fine with anonymous classes.
     */
    public static String simpleClassName(Class<?> clazz) {
        if (clazz == null) {
            return "null_class";
        }

        Package pkg = clazz.getPackage();
        if (pkg != null) {
            return clazz.getName().substring(pkg.getName().length() + 1);
        } else {
            return clazz.getName();
        }
    }
}

Related

  1. simpleClassName(Class cl)
  2. simpleClassName(Class klass)
  3. simpleClassName(Class clazz)
  4. simpleClassName(Class clazz)
  5. simpleClassName(Class type)
  6. simpleClassName(final String className)
  7. simpleClassName(Object o)