is Field Serializable - Android java.lang.reflect

Android examples for java.lang.reflect:Field

Description

is Field Serializable

Demo Code


//package com.java2s;
import java.io.Serializable;
import java.lang.reflect.Field;

public class Main {
    public static boolean isSerializable(Class<?> clazz) {
        if (isAssignableFrom(clazz, Serializable.class)) {
            return true;
        }//w ww  . ja  v a 2 s. co m
        return false;
    }

    public static boolean isSerializable(Field field) {
        return isSerializable(getFeildClass(field));
    }

    public static boolean isAssignableFrom(Class<?> clazz,
            Class<?> targetClazz) {
        if (targetClazz.isAssignableFrom(clazz)) {
            return true;
        }
        return false;
    }

    public static boolean isAssignableFrom(Field field, Class<?> targetClazz) {
        return isAssignableFrom(getFeildClass(field), targetClazz);
    }

    public static Class<?> getFeildClass(Field field) {
        return field.getType();
    }
}

Related Tutorials