Reputation: 49553
Is there any Java annotation enabling to intercept the access (read or write) to a public class attribute ?
This would enable to inject logic as you would with getters and setters, without the need of making them when it's not necessary.
Upvotes: 2
Views: 257
Reputation: 533492
There is no built in annotations to do this, but you could add your own. However, Using aspect orientated programming may be what you have in mind. e.g. AspectJ
Upvotes: 1
Reputation: 15189
No. Java does not provide any means to intercept the access of an attribute. With aspect oriented programming you can achieve something like this with methods but for attributes this is impossible.
Upvotes: 1