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 boolean isArray(final Object obj) {
    return obj != null && obj.getClass().isArray();
}

From source file:Main.java

public static boolean containsClass(Iterable<?> iterable, Class<?> classToSearch) {
    for (Object o : iterable) {
        if (o.getClass() == classToSearch) {
            return true;
        }/*from w  w  w  .  j a v a  2 s  .c  om*/
    }
    return false;
}

From source file:Main.java

public static boolean isActivityRecord(Object object) {
    return object != null && object.getClass().getSimpleName().endsWith("ActivityRecord");
}

From source file:Main.java

private static char getType(Object object) {
    String s = object.getClass().getName();
    for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) == '[') {
            continue;
        }//w  ww.  ja va2s  .c om
        return s.charAt(i);
    }
    return 0;
}

From source file:Main.java

private static boolean isDate(Object obj) {

    String fulname = obj.getClass().getName();
    if (fulname.contains("java.util.Date") || fulname.contains("java.sql.Date"))
        return true;

    return false;
}

From source file:Main.java

public static Class<?>[] toClasses(Object... args) {
    List<Class<?>> list = new ArrayList<Class<?>>(args.length);
    for (Object obj : args)
        list.add(obj.getClass());
    return list.toArray(new Class[list.size()]);
}

From source file:Main.java

/**
 * Retrieves the class name (to be used for serialization/deserialization
 * for the passed instance/*from   www .  j a va 2 s. c  om*/
 * @param target The instance to get the class name for
 * @return the target's class name
 */
public static String getClassName(Object target) {
    return target.getClass().getSimpleName();
}

From source file:SampleArrayReflection.java

static void printArrayNames(Object target) {
    Class targetClass = target.getClass();
    Field[] publicFields = targetClass.getFields();
    for (int i = 0; i < publicFields.length; i++) {
        String fieldName = publicFields[i].getName();
        Class typeClass = publicFields[i].getType();
        String fieldType = typeClass.getName();
        if (typeClass.isArray()) {
            System.out.println("Name: " + fieldName + ", Type: " + fieldType);
        }/*from www  .  j  av a 2  s  .  c  om*/
    }
}

From source file:Main.java

public static String[] getPropertyNames(Object object) {
    Field[] fields = object.getClass().getDeclaredFields();
    String[] propertyNames = new String[fields.length];
    for (int i = 0; i < fields.length; i++) {
        propertyNames[i] = fields[i].getName();
    }/*from  w w w  . j  a  v a  2s .  c o m*/
    return propertyNames;
}

From source file:Main.java

/**
 * Clean-up the class name/*from  w  w  w .jav  a  2 s . c  o  m*/
 * 
 * @param o
 * @return
 */
private static String getClassName(Object o) {
    String className = o.getClass().getName();
    int pos = className.indexOf('$');
    if (pos != -1) {
        className = className.substring(0, pos);
    }
    return className;
}