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

com.github.tcurrie.rest.factory.proxy.Fields Maven / Gradle / Ivy

There is a newer version: 0.2.70
Show newest version
package com.github.tcurrie.rest.factory.proxy;

import com.github.tcurrie.rest.factory.Strings;
import com.github.tcurrie.rest.factory.v1.RestFactoryException;

import java.lang.reflect.Field;

@SuppressWarnings("WeakerAccess")
public class Fields {
    private Fields() {
        throw new RestFactoryException("Can not construct instance of Factory class.");
    }
    public static  T getField(final U instance, final String fieldName) {
        try {
            final Field field = instance.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            //noinspection unchecked
            return (T) field.get(instance);
        } catch (final Exception e) {
            throw new RestFactoryException(Strings.format("Invalid field name [{}].", fieldName), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy