Example usage for java.lang Object getClass

List of usage examples for java.lang Object getClass

Introduction

In this page you can find the example usage for java.lang Object getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static int getLengthOfCollection(Object value) {
    if (isArray(value.getClass())) {
        return Array.getLength(value);
    } else {/*from ww  w.  ja v a2 s . c  om*/
        return ((Collection<?>) value).size();
    }
}

From source file:Main.java

public static String getThreadName(Object who, int instanceCount) {
    Class<?> objClass = who.getClass();
    return objClass.getSimpleName() + "_" + getHashCode(who) + "_" + instanceCount;
}

From source file:Main.java

public static <T> Type whatsMyGenericType(Object object) {
    return (Class<T>) ((ParameterizedType) object.getClass().getGenericSuperclass())
            .getActualTypeArguments()[0];
}

From source file:Main.java

public static void log(Object sender, String log) {
    System.out.println("Class:" + sender.getClass().getSimpleName());
    System.out.println("Log:" + log);
}

From source file:MethodInfoDemo.java

/**
 * __UNDOCUMENTED__/*from www  .java2s  .c  o  m*/
 * 
 * @param obj
 *          __UNDOCUMENTED__
 */
public static void printMethodInfo(final Object obj) {
    Class type = obj.getClass();
    final Method[] methods = type.getMethods();
    for (int idx = 0; idx < methods.length; idx++) {
        System.out.println(methods[idx]);
    }
}

From source file:Main.java

private static String getPackageCodePath(Object context) {
    try {/* ww  w  .  j  a v a 2  s . co m*/
        return (String) context.getClass().getMethod("getPackageCodePath").invoke(context);
    } catch (Exception ignore) {
    }
    return null;
}

From source file:Main.java

public static void logErrorStackTrace(Object source, Exception e, String msg) {
    String tag = source.getClass().getSimpleName();
    Log.e(tag, msg + ": " + e.getClass().getSimpleName() + ":");
    Log.e(tag, Log.getStackTraceString(e));
}

From source file:Main.java

private static void addStartLine(Object aObject, StringBuilder aResult) {
    aResult.append(aObject.getClass().getName());
    aResult.append(" {");
    aResult.append(NEW_LINE);//from  w  w  w  .  ja  v a2s.  com
}

From source file:Main.java

public static String getId(Object t) {
    try {//from w  w w.  j  a  v  a 2  s  .c o m
        Field idField = t.getClass().getDeclaredField("id");
        idField.setAccessible(true);
        return idField.get(t).toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isToStringable(Object valueObj) {
    try {// w ww  .  ja  va 2s .c o  m
        if (valueObj.getClass().getPackage().getName().startsWith("java.lang"))
            return true;
    }

    catch (Exception ex) {
        ex.printStackTrace();
    }

    return false;
}