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

com.github.bingoohuang.sqltrigger.ReflectUtil Maven / Gradle / Ivy

The newest version!
package com.github.bingoohuang.sqltrigger;

import lombok.SneakyThrows;
import lombok.val;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectUtil {
    @SneakyThrows
    public static Object invokeMethod(Method method, Object obj, Object... args) {
        return method.invoke(obj, args);
    }

    @SneakyThrows
    public static void setField(Field field, Object obj, Object value) {
        if (!field.isAccessible()) field.setAccessible(true);
        field.set(obj, value);
    }

    public static Field findField(Class type, String fieldName) {
        for (val field : type.getDeclaredFields()) {
            if (field.getName().equals(fieldName)) return field;
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy