Creating immutable objects from javabean

Posted by redzedi on Stack Overflow See other posts from Stack Overflow or by redzedi
Published on 2009-04-15T19:41:16Z Indexed on 2010/03/24 21:53 UTC
Read the original article Hit count: 156

Filed under:
|
|

Hi All, I am involved in this project where we are building on good bit of legacy code. I have a particular situation about one big java bean object which has to be transferred over wire. So my first thought was to make it immutable and serializable to do the trick .At this point I am faced with a few difficult choices :-

1> Ideally I want some way to automatically generate an immutable, serializable version of this class. I dont have the scope to refactor or alter this class in any way and i would really really hate to have to copy paste the class with a different name ??

2> Assuming that i gave up on 1 i.e i actually chose to duplicate code of the HUGE javabean class , i still will be in the unsavoury situation of having to write a constructor with some 20-25 parameters to make this class immutable. what is a better way to make a class immutable other than constructor injection ??

Thanks and Regards,

© Stack Overflow or respective owner

Related posts about javabeans

Related posts about immutability