KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get the fields and values of my object's first parent. My current code is this: Class<? extends Object> cls = obj.getClass(); Field[] fields = cls.getDeclaredFields(); for ( Field field : fields ) { String fieldName = field.getName(); String fieldValue = field.get(obj); } My class structure is similar to this: class A { int x; } class B extends A { int y; } class C extends B { int z; } Now, I pass a C object to the method and I want to get all fields from C and B, but not from A. Is there a way to do this (using reflection, I don't want to implement other methods)?
Tags (comma-separated)
Save Edits
Cancel