Results 1 to 3 of 3

Thread: Cloning issue

  1. #1
    Paul Richards is offline Member
    Join Date
    Oct 2008
    Location
    UK
    Posts
    65
    Rep Power
    0

    Default Cloning issue

    The clone method in OrderedCloneablePair does not work since the clone method on the members e1 and e2 is returning an Object. Why does it not return a member of class E?

    Java Code:
    public class CloneablePair<E extends ReallyCloneable> {
        private E e1,e2;
    
        public CloneablePair(E e1, E e2) {
            this.e1 = e1;
            this.e2 = e2;
        }
    
        public CloneablePair clone() {
            return new CloneablePair(e1.clone(), e2.clone());
        }
    }
    
    public interface ReallyCloneable<X> {
         public X clone();
    }
    Last edited by Paul Richards; 08-23-2009 at 11:00 PM.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Because you didn't tell it what class is ReallyCloneable?

    Java Code:
    public class CloneablePair<E extends ReallyCloneable<E>>
    {
       private E e1,e2;
    
       public CloneablePair(E e1, E e2) 
       {
          this.e1 = e1;
          this.e2 = e2;
       }
    
       public CloneablePair<E> clone() {
          return new CloneablePair(e1.clone(), e2.clone());
       }
    }
    
    public interface ReallyCloneable<X> {
         public X clone();
    }

  3. #3
    Paul Richards is offline Member
    Join Date
    Oct 2008
    Location
    UK
    Posts
    65
    Rep Power
    0

Similar Threads

  1. Cloning problem in Java
    By jralexander137 in forum New To Java
    Replies: 18
    Last Post: 10-30-2008, 10:52 PM
  2. Help with Deep Cloning
    By jralexander137 in forum New To Java
    Replies: 6
    Last Post: 10-30-2008, 05:34 PM
  3. folder cloning
    By jad in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2008, 12:28 AM
  4. Cloning objects
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-04-2008, 09:33 AM
  5. Cloning in Java
    By gchalpatirao in forum Advanced Java
    Replies: 0
    Last Post: 08-14-2007, 03:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •