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 void fieldSet(Object object, String fieldName, Object value) throws Exception {
    Field field = object.getClass().getDeclaredField(fieldName);
    field.setAccessible(true);//from ww  w  . j a  va2s.c  o m
    field.set(object, value);
}

From source file:Main.java

public static boolean hasCuotes(Object value) {
    return getDataBaseType(value.getClass()).equals(TEXT);
}

From source file:com.sunchenbin.store.feilong.core.lang.ObjectUtil.java

/**
 * ?./*from  www  .j av a 2  s .c o  m*/
 *
 * @param object
 *            the object
 * @return true, if checks if is array
 * @since 1.3.0
 */
public static Boolean isArray(Object object) {
    return object.getClass().isArray();
}

From source file:Main.java

public static Object getFieldValue(final Object object, final String name) throws Exception {
    Field field = object.getClass().getDeclaredField(name);
    field.setAccessible(true);//w  w  w  . j  a  v a 2 s .c  o  m
    return field.get(object);
}

From source file:Main.java

/**
 * Returns a new array of given size, containing as many elements of
 * the original array as it can hold. N.B. Always returns a new array
 * even if newsize parameter is the same as the old size.
 */// w w w . j a  v  a 2  s.co  m
public static Object resizeArray(Object source, int newsize) {

    Object newarray = Array.newInstance(source.getClass().getComponentType(), newsize);
    int oldsize = Array.getLength(source);

    if (oldsize < newsize) {
        newsize = oldsize;
    }

    System.arraycopy(source, 0, newarray, 0, newsize);

    return newarray;
}

From source file:Main.java

public static String saveObjectToXmlString(Object obj) throws JAXBException {
    final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    final StringWriter writer = new StringWriter();
    m.marshal(obj, writer);/*from  w  w w.  j  av a  2s. c  om*/

    return writer.toString();
}

From source file:HiddenFieldModification.java

/** 
 * Sets all int fields in an object to 0.
 *
 * @param obj The object to operate on.//w w  w  .  j  a  va 2  s  . co  m
 *
 * @throws RuntimeException If there is a reflection problem.
 */
public static void initIntFields(final Object obj) {
    try {
        Field[] fields = obj.getClass().getDeclaredFields();
        for (int idx = 0; idx < fields.length; idx++) {
            if (fields[idx].getType() == int.class) {
                fields[idx].setAccessible(true);
                fields[idx].setInt(obj, 0);
            }
        }
    } catch (final IllegalAccessException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

public static boolean isAssignable(Object obj, Class<?> clazz) {
    return isAssignable(obj == null ? null : obj.getClass(), clazz);
}

From source file:Main.java

public static Object getSIGNAL_STRENGTH_NAMES(Object instance) {
    try {//from  w w  w  .j  a  v a  2s . c  o m
        Field f = getField(instance.getClass(), "SIGNAL_STRENGTH_NAMES");
        return f.get(instance);
    } catch (NoSuchFieldException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:SerializeJavaObjects_MySQL.java

public static Object readJavaObject(Connection conn, long id) throws Exception {
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL);
    pstmt.setLong(1, id);//from  w  ww.ja v a2s . com
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    Object object = rs.getObject(1);
    String className = object.getClass().getName();

    rs.close();
    pstmt.close();
    System.out.println("readJavaObject: done de-serializing: " + className);
    return object;
}