Java Object to String objectToString(Object o)

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

Description

Emulate Object.toString on an object even if toString() was overridden.

License

Open Source License

Parameter

Parameter Description
o Object.

Return

A string similar to o.toString() with the Object.toString() version of the method, or "null" if o is null.

Declaration

public static String objectToString(Object o) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU Lesser General Public License as published

public class Main {
    /**//from  w  w  w  .ja  v a 2 s.c  om
     * Emulate <code>Object.toString</code> on an object even if <code>toString()</code> was
     * overridden.
     * 
     * @param o Object.
     * 
     * @return A string similar to <code>o.toString()</code> with the <code>Object.toString()</code>
     *   version of the method, or &quot;null&quot; if <code>o</code> is <code>null</code>.
     */
    public static String objectToString(Object o) {

        if (o == null)
            return "null";

        return o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o));
    }
}

Related

  1. objectToString(Object a_Object)
  2. objectToString(Object in)
  3. objectToString(Object in, boolean ignoreNull)
  4. objectToString(Object o)
  5. objectToString(Object o)
  6. objectToString(Object o, boolean quoteStrings)
  7. objectToString(Object obj)
  8. objectToString(Object obj)
  9. objectToString(Object obj)