sixlegs.com / blog / java / immutable-beans.html

Root Beer Logo Root Beer

Chris Nokleberg's Fizzy Weblog

October 2003
Su M Tu W Th F Sa
      1 2 3 4
6 7 8 9 10 11
12 13 14 15 17 18
19 20 21 22 23 24 25
26 27 29 30 31
Previous  |  Next  |  More...
#  Immutable beans

There has been some discussion recently that has touched on the idea of immutable beans. In a lot of frameworks beans are used for configuration (for example the Spring framework), but often you want to "lock down" the beans after they have been initialized. I've added a new ImmutableBean class to CGLIB CVS that generates a new version of the bean where any call to a setter will throw an exception:

MyBean readWrite = new MyBean();
  readWrite.setFoo(42);
  MyBean readOnly = (MyBean)ImmutableBean.create(readWrite);
  readOnly.setFoo(42);  // this will throw an exception

I also added a BeanCopier class, see my message to the Jakarta commons-devel mailing list for details. In summary it is 800 times faster than the BeanUtils version [Emoticon]

[Powered By FreeMarker]  [Valid Atom 1.0]  [Weblog Commenting by HaloScan.com]