ReflectiveAttribute extends SimpleAttribute<O, A> { static Field getField(Class<?> cls, String fieldName) throws NoSuchFieldException { while (cls != null && cls != Object.class) { try { return cls.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { cls = cls.getSuperclass(); } } throw new NoSuchFieldException("No such field: " + fieldName); } ReflectiveAttribute(Class<O> objectType, Class<A> fieldType, String fieldName); @Override A getValue(O object, QueryOptions queryOptions); @Override boolean equals(Object o); @Override boolean canEqual(Object other); @Override int hashCode(); static ReflectiveAttribute<O, A> forField(Class<O> objectType, Class<A> fieldType, String fieldName);  }
@Test public void testGetInheritedField() throws NoSuchFieldException { Assert.assertEquals("foo", ReflectiveAttribute.getField(Bar.class, "foo").getName()); Assert.assertEquals("bar", ReflectiveAttribute.getField(Bar.class, "bar").getName()); NoSuchFieldException expected = null; try { ReflectiveAttribute.getField(Bar.class, "baz"); } catch (NoSuchFieldException nsfe) { expected = nsfe; } Assert.assertNotNull(expected); }