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

net.serenitybdd.jbehave.reflection.Extract Maven / Gradle / Ivy

There is a newer version: 1.46.0
Show newest version
package net.serenitybdd.jbehave.reflection;

import java.lang.reflect.Field;

public class Extract {

    private final String fieldName;

    private Extract(String fieldName) {
        this.fieldName = fieldName;
    }

    public static Extract field(String fieldName) {
        return new Extract(fieldName);
    }

    public Object from(Object object) {
        try {
            Field field = object.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(object);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy