nullify Field - Java Reflection

Java examples for Reflection:Field

Description

nullify Field

Demo Code


//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static <E> void nullifyField(final E entity, final Field field)
            throws Exception {
        if (field.getType().isEnum() || field.getType().isPrimitive()) {
            return;
        }/* ww w . j a  v  a 2  s .c  o  m*/
        field.setAccessible(true);
        field.set(entity, null);
    }
}

Related Tutorials