Reputation: 89
Here is a class design: http://pastebin.com/1RSdmtXi
If i put only A
to class Expect I would like to see only A's getters and setters, or vica vera to B. If put in A
and B
, then all of getters and setters should be visible.
So an example for only A
:
A[] aExampe = {new A("Tim",1)};
Expect exp = new Expect(aExampe);
exp.getA(); --> visible
exp.getB(); --> not visible
You may advice another design for this.
Upvotes: 0
Views: 102
Reputation: 7282
Why this is a need?
If you change the class Expect
(by adding an removing fields), you can add and remove getters and setters too.
If you want to change the class without modifying and recompiling client classes, define an interface containing all needed methods, implement it by Expect
class, and instead of removing the methods, just make them empty methods (without any body).
By this pattern, you will not use compile time checking, and won't need to use dirty reflection for normal method calls.
Upvotes: 1
Reputation: 5692
Try using this:
Expect.class.getMethod("getA", null).setAccessible(true);
Expect.class.getMethod("getB", null).setAccessible(false);
But I suggest you to change your architecture.
Upvotes: 1
Reputation: 7600
In the class Expect you should only have getA(), setA, getB and setB, not all the getters and setters for A and B's attributes. Those ones belong to those classes.
Upvotes: 0