Rocky
Rocky

Reputation: 1287

How to list component fields in a class

If I give you a class like:

public class A {
        protected ClassType a1;
        protected ClassType a2;
        protected int a3;
    }
    public class B {
        protected ClassType b1;
        protected EnumType b2;
        protected boolean b3;
    }
    public enum C {
        c1,
        c2,
        c3
    }
    public class All {
        protected ClassType A;
        protected ClassType B;
        protected EnumType C;
    }

How can I write a function through which class object "All" is passed,,,like "foo(All all);" to get all the members' names(like "A") in "all" including its member's member's name?

I don't know if I made that clear.

Thanks in advance ! :-)

Upvotes: 0

Views: 75

Answers (1)

RAY
RAY

Reputation: 7110

You don't need an instance of all. Just the class object. Use the getDeclaredFields method

Upvotes: 2

Related Questions