Say, I have a method that returns a custom List
with some objects. They are returned as Object
to me. I need to get value of a certain field from t
I strongly recommend using Java generics to specify what type of object is in that List, ie. List
. If you have Cars and Trucks you can use a common superclass/interface like this List
.
However, you can use Spring's ReflectionUtils to make fields accessible, even if they are private like the below runnable example:
List
Running this has an output of:
value=[C@1b67f74
value=3