private Object readField(String tagName, Object obj) {
        Class<?> cls = obj.getClass();
        try {
            return cls.getField(tagName)
                      .get(obj);
        } catch (NoSuchFieldException ignored) {
            try {
                return cls.getMethod(tagName)
                          .invoke(obj);
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException(e);
            } catch (InvocationTargetException e) {
                throw new IllegalArgumentException(e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(e);
            }
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(e);
        }
    }
A single class templating library for doing runtime code-gen.

Not Threadsafe.
jctools-channels/src/main/java/org/jctools/util/Template.java