title: How can i make a class Immutable if it has a instance variable of java.lang.Object?
body: <pre><code>final public class ImmutableWithObject {
  
      final Object obj;
      final List myList;
  
      ImmutableWithObject(Object obj1, List list)
      {
          this.obj = obj1;
          this.myList = ((List) ((ArrayList) list).clone());
      }
  
      public Object getObj() {
          return this.obj;
      }
  
      public List getMyList() {
          return (List) ((ArrayList&lt;String&gt;) this.myList).clone();
      }
  
      public static void main(String[] args) {
  
          ImmutableWithObject io = new ImmutableWithObject(new Date(), new ArrayList());
  
          ((Date) io.getObj()).setDate(22);
  
          System.out.println((Date) io.getObj());
      }
  }
  </code></pre>
  
  
  
  <pre><code>o/p : Mon Aug 22 00:50:04 IST 2011
  </code></pre>
  
  <p>which is incorrect.</p>