Example usage for java.lang.reflect Field getType

List of usage examples for java.lang.reflect Field getType

Introduction

In this page you can find the example usage for java.lang.reflect Field getType.

Prototype

public Class<?> getType() 

Source Link

Document

Returns a Class object that identifies the declared type for the field represented by this Field object.

Usage

From source file:Main.java

public static boolean isLong(Field field) {
    return field.getType() == long.class || field.getType() == Long.class;
}

From source file:Main.java

public static boolean isInteger(Field field) {
    return field.getType() == int.class || field.getType() != Integer.class;
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class clazz = field.getType();
    return clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class)
            || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class)
            || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(Boolean.class)
            || clazz.equals(Date.class) || clazz.equals(Date.class) || clazz.equals(java.sql.Date.class)
            || clazz.isPrimitive();/*from www.  j av a  2  s .  c  om*/
}

From source file:Main.java

public static boolean isSerializable(Field f) {
    Class<?>[] cls = f.getType().getInterfaces();
    for (Class<?> c : cls) {
        if (Serializable.class == c) {
            return true;
        }//  w w w  .ja v  a  2 s  . c  om
    }
    return false;
}

From source file:Main.java

/**
 * /*w w w .  j  a va2s .  com*/
 * @param field
 * @return
 */
public static Class<?> getFieldType(Field field) {
    Class<?> fieldType = field.getType();
    return fieldType;
}

From source file:Main.java

/**
 * @param field/*from ww w .  j a  v a 2  s .c  o m*/
 * @return
 */
public static String getGetIsPrefix(Field field) {
    if (field.getType() == Boolean.class || field.getType() == boolean.class)
        return "is";
    else
        return "get";
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class)
            || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class)
            || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(Boolean.class)
            || clazz.equals(Date.class) || clazz.equals(Date.class) || clazz.equals(java.sql.Date.class)
            || clazz.isPrimitive();// www.j ava  2s  . co m
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class)
            || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class)
            || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(Boolean.class)
            || clazz.equals(Date.class) || clazz.equals(java.util.Date.class)
            || clazz.equals(java.sql.Date.class) || clazz.isPrimitive();
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(Integer.class) || clazz.equals(int.class) || clazz.equals(Byte.class)
            || clazz.equals(byte.class) || clazz.equals(Character.class) || clazz.equals(char.class)
            || clazz.equals(Long.class) || clazz.equals(long.class) || clazz.equals(Double.class)
            || clazz.equals(double.class) || clazz.equals(Float.class) || clazz.equals(float.class)
            || clazz.equals(Short.class) || clazz.equals(short.class) || clazz.equals(Boolean.class)
            || clazz.equals(boolean.class) || clazz.equals(Date.class) || clazz.equals(java.sql.Date.class)
            || clazz.isPrimitive() || clazz.equals(String.class);
}

From source file:Main.java

/**
 * Returns the generic class of multi-value objects.
 * //from  ww w. j a va  2s  . c o  m
 * @param p
 *          Field to examine
 * @return The Class<?> of generic type if any, otherwise null
 */
public static Class<?> getGenericMultivalueType(final Field p) {
    if (p.getType() instanceof Class<?>) {
        final Type genericType = p.getGenericType();
        if (genericType != null && genericType instanceof ParameterizedType) {
            final ParameterizedType pt = (ParameterizedType) genericType;
            if (pt.getActualTypeArguments() != null && pt.getActualTypeArguments().length > 0) {
                if (((Class<?>) pt.getRawType()).isAssignableFrom(Map.class)) {
                    if (pt.getActualTypeArguments()[1] instanceof Class<?>) {
                        return (Class<?>) pt.getActualTypeArguments()[1];
                    } else if (pt.getActualTypeArguments()[1] instanceof ParameterizedType)
                        return (Class<?>) ((ParameterizedType) pt.getActualTypeArguments()[1]).getRawType();
                } else if (pt.getActualTypeArguments()[0] instanceof Class<?>) {
                    return (Class<?>) pt.getActualTypeArguments()[0];
                } else if (pt.getActualTypeArguments()[0] instanceof ParameterizedType)
                    return (Class<?>) ((ParameterizedType) pt.getActualTypeArguments()[0]).getRawType();
            }
        } else if (p.getType().isArray())
            return p.getType().getComponentType();
    }
    return null;
}