Is it possible to add “hooks” to a class via bytecode enhancement that execute code whenever a class field is read or written? For example, I’d like to automatically set a “dirty” flag whenever a new value is assigned to a field.
If so, which libraries are best suited to implement this functionality?
Here is how to generate getters and setters using the ASM framework. That should get you started.
You can even let your bytecode-rewriter hook into the class-loader and do the rewriting on the fly.