Java Class Name Get className(Object o)

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

Description

Readable class name (i.e., not unqualified)

License

Open Source License

Parameter

Parameter Description
o may be null

Return

readable String class name

Declaration

public static String className(Object o) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005-2012 eBay Inc.//from   w  w w  .  jav  a  2  s .c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/

public class Main {
    /**
     * Readable class name (i.e., not unqualified)
     * 
     * @param o
     *            may be null
     * @return readable String class name
     */
    public static String className(Object o) {
        if (null == o) {
            return "NOCLASS";
        }
        if (o instanceof Class) {
            return ((Class<?>) o).getSimpleName();
        }
        // implemetn short/long name policy for those who don't care
        return o.getClass().getSimpleName();

    }
}

Related

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