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

com.miragesql.miragesql.util.ReflectionUtil Maven / Gradle / Ivy

Go to download

Mirage-SQL is an easy and powerful SQL centric database access library for Java (or JVM based languages) which provides dynamic SQL templates in plain SQL files.

There is a newer version: 2.1.2
Show newest version
package com.miragesql.miragesql.util;

import java.lang.reflect.Field;
import java.lang.reflect.Type;

public class ReflectionUtil {

    public static Field getField(Class clazz, String name){
        while(clazz != Object.class){
            try {
                Field field = clazz.getDeclaredField(name);
                if(field != null){
                    return field;
                }
            } catch(Exception ex){
                // ignore
            }
            clazz = clazz.getSuperclass();
        }
        return null;
    }

    public static Class getElementTypeOfList(final Type parameterizedList) {
        return GenericUtil.getRawClass(GenericUtil
                .getElementTypeOfList(parameterizedList));
    }

    public static Class getElementTypeOfListFromFieldType(final Field field) {
        final Type type = field.getGenericType();
        return getElementTypeOfList(type);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy