Application of the Propertychangesupport attribute value modified by the JDK in the Observer mode

Source: Internet
Author: User
Import java.beans.PropertyChangeEvent;
Import Java.beans.PropertyChangeListener;

Import Java.beans.PropertyChangeSupport;
	
	public class Propertychangesupporttest {static Testbean Testbean = new Testbean (); public static void Main (string[] args) {Propertychangesupport propertychangesupport = new Propertychangesupport (testbea
		n); Propertychangesupport.addpropertychangelistener (New PropertyChangeListener () {@Override public void PropertyChange ( Propertychangeevent evt) {if (Evt.getpropertyname (). Equals ("name")) {System.out.println ("bean:" + propertychanges UpportTest.this.testBean + "field:" + evt.getpropertyname () + "value Change,old value:" + evt.getoldvalue () + "New Valu
				E: "+ evt.getnewvalue ());
		}
			}
			
		});
		Testbean.setid (111);
		Testbean.setname ("Mike"); Propertychangesupport.firepropertychange ("name", "", "Mike");
		Notifies the property that the value has been modified to notify the relevant listener for processing} public static class testbean{private int id;
		private String name;
		public int getId () {	return ID;
		The public void setId (int id) {this.id = ID;
		Public String GetName () {return name;
		public void SetName (String name) {this.name = name; }
	}
}
This is the JDK application scenario for the Observer model, and in our usual projects, for example, in order to achieve dynamic loading of application configurations, we need to notify the application points that apply this parameter to make the corresponding changes when applying the configuration parameters that are applied dynamically after startup. Then you can use this propertychangesupport to do it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.