mercredi 2 mars 2016

java Field change listener

So I would really want some way of detecting Field changes of a certain object. I have googled for quite a while but haven't found anything. So basically all I need to know, is when some variable of a class changed. lets take this class for instance:

public class Example{
    String text = "test";

    public static void main(String[] args){
        Example e = new Example();
        e.text = "something else";
    }
}

I would basically want to detect when the 'text' variable has changed. I know many of you would say use getters and setters and such, this is not what I want though.

For a reason I can't easily explain, I need to be able to detect the field change from outside the class. Currently I am thinking of using a second thread that basically just scans a list of objects continuously and use reflection to detect changes that way, but that will obviously make the program heavier than it has to be.

So I hope there is a way of just creating listeners for field changes, does anyone know about libraries/systems/methods to do this?





Aucun commentaire:

Enregistrer un commentaire