Java Class Name Get className(final Class c)

Here you can find the source of className(final Class c)

Description

Get an easy-to-use representation of a class.

License

Open Source License

Parameter

Parameter Description
c the class

Return

the name

Declaration

public static final String className(final Class<?> c) 

Method Source Code

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

public class Main {
    /**// www  .  jav  a2 s .co  m
     * Get an easy-to-use representation of a class.
     *
     * @param c
     *          the class
     * @return the name
     */
    public static final String className(final Class<?> c) {
        String s;

        if (c == null) {
            return "No class specified."; //$NON-NLS-1$
        }

        s = c.getCanonicalName();
        if ((s != null) && (s.length() > 0)) {
            return s;
        }

        s = c.getName();
        if ((s != null) && (s.length() > 0)) {
            return s;
        }

        s = c.getSimpleName();
        if ((s != null) && (s.length() > 0)) {
            return s;
        }

        s = c.toString();
        if ((s != null) && (s.length() > 0)) {
            return s;
        }
        return "nameless"; //$NON-NLS-1$
    }
}

Related

  1. classname(Class javaClass)
  2. className(Class type)
  3. className(Class aClass)
  4. className(final Object object)
  5. className(Object o)
  6. className(Object o)
  7. classname(Object obj)