Java Identity to String identityToString(Object obj)

Here you can find the source of identityToString(Object obj)

Description

Return a String representation of an object's overall identity.

License

Open Source License

Parameter

Parameter Description
obj the object (may be <code>null</code>)

Return

the object's identity as String representation, or an empty String if the object was null

Declaration

public static String identityToString(Object obj) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String EMPTY_STRING = "";

    /**//from w w w  .j  ava 2 s  .c om
     * Return a String representation of an object's overall identity.
     * @param obj the object (may be <code>null</code>)
     * @return the object's identity as String representation,
     * or an empty String if the object was <code>null</code>
     */
    public static String identityToString(Object obj) {
        if (obj == null) {
            return EMPTY_STRING;
        }
        return obj.getClass().getName() + "@" + getIdentityHexString(obj);
    }

    /**
     * Return a hex String form of an object's identity hash code.
     * @param obj the object
     * @return the object's identity code in hex notation
     */
    public static String getIdentityHexString(Object obj) {
        return Integer.toHexString(System.identityHashCode(obj));
    }
}

Related

  1. identityToString(final Object o)
  2. identityToString(final Object obj)
  3. identityToString(Object obj)
  4. identityToString(Object obj)
  5. identityToString(Object pObject)
  6. identityToString(StringBuffer buffer, Object object)
  7. identityToSubject(String identity)