How to make a Java Bean immutable?

Hi How do I make a Java Bean immutable? Is there anyway I can do it? What could be the possible ways to do this? If for example, my Java Bean has a List property also. then how would it change.....Pleae help.
[229 byte] By [ruuddina] at [2007-10-3 2:53:10]
# 1
Make the member variables private and don't provide any public setter methods. As an added measure, make the fields final.
jverda at 2007-7-14 20:42:13 > top of Java-index,Java Essentials,New To Java...
# 2

For the list property, the getter should return a copy of the list, e.g. with ArrayList's clone() method or copy constructor. Additionally, if the list's elements are immutable, you'll want to copy them, if possible. For example, if you have a list of java.util.Date, then even with a clone of the list, both lists will be pointing to the same Date objects, so if you call Date.setTime, both lists will see it, so you'd need to copy each date element, a la public List getDates() {

List result = new ArrayList();

for (Iterator iter = originalList.iterator(); iter.hasNext();) {

Date originalDate = (Date)iter.next();

Date newDate = new Date(originalDate.getTime()); // or something--check Date's docs

result.add(newDate);

}

}

jverda at 2007-7-14 20:42:13 > top of Java-index,Java Essentials,New To Java...
# 3
Very well.... Thanks jverd... this is really helpful
ruuddina at 2007-7-14 20:42:13 > top of Java-index,Java Essentials,New To Java...