I was trying to find a private
field using reflection with a given name, which may also reside in parent class or somewhere else in the inheritance hierarchy.
But I found out that there is no such method in Class
which provides this information.
Class#getDeclaredFields()
- provides all fields private
, public
but does not include inheritance hierarchy
Class#getFields()
- includes inheritance hierarchy but searches only public
fields.
So why is there no method that provides both types of information?
I know this can easily be implemented and there are libraries that provide this, but still can be included in java itself.