Java Class Simple Name Get simpleClassName(Object o)

Here you can find the source of simpleClassName(Object o)

Description

The shortcut to #simpleClassName(Class) simpleClassName(o.getClass()) .

License

Open Source License

Declaration

public static String simpleClassName(Object o) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  w w . ja v a 2  s  . c  o  m
     * The shortcut to {@link #simpleClassName(Class)
     * simpleClassName(o.getClass())}.
     */
    public static String simpleClassName(Object o) {
        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) {
        Package pkg = clazz.getPackage();
        if (pkg != null) {
            return clazz.getName().substring(pkg.getName().length() + 1);
        } else {
            return clazz.getName();
        }
    }
}

Related

  1. simpleClassName(Class clazz)
  2. simpleClassName(Class clazz)
  3. simpleClassName(Class type)
  4. simpleClassName(final String className)
  5. simpleClassName(Object o)
  6. simpleClassName(Object object)
  7. simpleClassName(String fqn)
  8. simpleClassNameAndHashCodeString(Object object)
  9. simpleClassNameAndHashCodeString(Object object)