All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spring.turbo.util.reflection.FieldUtils Maven / Gradle / Ivy

The newest version!
package spring.turbo.util.reflection;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * 反射工具 - Field
 *
 * @author 应卓
 * @see FieldPredicateFactories
 * @see ConstructorUtils
 * @see MethodUtils
 * @since 1.2.1
 */
public final class FieldUtils {

    /**
     * 私有构造方法
     */
    private FieldUtils() {
        super();
    }

    // -----------------------------------------------------------------------------------------------------------------

    public static void makeAccessible(Field field) {
        ReflectionUtils.makeAccessible(field);
    }

    // -----------------------------------------------------------------------------------------------------------------

    public static List find(Class clazz) {
        final List list = new ArrayList<>();
        ReflectionUtils.doWithFields(clazz, list::add);
        return list;
    }

    public static List find(Class clazz, String name) {
        final List list = new ArrayList<>();
        final Field field = ReflectionUtils.findField(clazz, name);
        if (field != null) {
            list.add(field);
        }
        return list;
    }

    public static List find(Class clazz, String name, Class fieldType) {
        final List list = new ArrayList<>();
        final Field field = ReflectionUtils.findField(clazz, name, fieldType);
        if (field != null) {
            list.add(field);
        }
        return list;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy