I understand that you want a "generic" thing like: iterate a whole list; then retrieve a field of an object via name; to then check if any of the elements has a matching thing.
I think there is no such thing in Hamcrest: as that is ay too complicated for a pre-defined matcher.
In that sense, the only "answer" to exactly this requirement would be to create your own customer matcher that uses reflection to actually do that.
More details: you can start with an older answer of mine that contains a ready to use matcher that works for lists.
Actually, the only thing left to do now: change my list matcher to perform a different kind of check. And there you could make use of the Apache Commons EqualsBuilder listed in the other answer.
There should be no big hurdle in implementing that; its just "work".
But: I am not sure if that is really the correct approach. As said; the question you are trying to solve there sounds very specific too me; and you know: any unit test that uses reflection lacks the same problem that any "reflection based" code has - the compiler will not tell you, when somebody changes your production code; for example by changing the name of the field name
.
Thus: instead of using reflection, I would rather compromise on the "production code" side of things; for example by adding a simple getter:
public class Emp {
... fields
String getName() { return name; }
And instead of using reflection to compare generic properties, you write a matcher that knows to use that getter to fetch names and compare them.h