How to detect changing of attributes in a class?
here is my problem with a Java program: I have two classes (let's 开发者_如何学JAVAcall them Ob1 and Ob2), both with an integer and other attributes. Ob2 has an attributs 'ob1', which is an instance of Ob1. Ob1 creates Ob2, giving itself as 'ob1'. I want that as the integer of Ob1 is equal to integer of Ob2, something happens. How can I do? Thanks.
Simple answer: you cannot. Nothing in Java will notify anything else about a change in the value of a field.
Second answer: the integers in your class are private and only modified via 'set' functions, the set functions can make the check and make a call for you.
精彩评论