Is there a way to define a method, which is called everytime I call a get?
I have an Object Contact and don't want to set updateLastUsed(); in about 30 Getters for my Members.
Instead of accessing the getter for your properties, you could create one general getter that takes the property name as an input. The return type would need to be Object if your properties are of different types.
In this general getter you call the property getter and the updateLastUsed() method. To be safe make all property getters private.
I would have suggested AOP but if it's J2ME we're talking about you're most likely better off manually inserting "onGetCalled()" in each of your 30 accessors and then coding whatever you need within that method. You may want to pass in name of the method being called (or property accessed) in case you need it in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With