java - Bytecode manipulation to intercept setting the value of a field -


using library asm or cglib, there way add bytecode instructions class execute code whenever value of class field set?

for example, let’s have class:

    public class person    {          bool dirty;        public string name;        public date birthdate;        public double salary;    } 

let’s section of code contains line:

person.name = "joe";

i want instruction intercepted dirty flag set true. know possible setter methods -- person.setname (“joe”) -- class methods can modified bytecode manipulation, want same thing field.

is possible, , if so, how?

edit

i want avoid modifying code section accesses class, i'm looking way keep interception code part of person class. there pseudo-methods field access, similar properties in python classes?

there 2 bytecodes updating fields: putfield , putstatic (see http://java.sun.com/docs/books/jvms/second_edition/html/instructions2.doc11.html). these found in code using class, there's no way modify person.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -