Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] CLONE


  • From: marc.tremblay@xxxxxxxxx (Marc Tremblay)
  • Subject: [Advanced-java] CLONE
  • Date: Tue, 29 Jan 2002 10:47:42 -0700

You can certainly use instanceof with Cloneable, as you can with any
interface.

Casting Message to Object and calling clone() won't make any difference from
calling clone on a Message.

As for Message not being an Object, that's not true.  Any class that
implements Message will be an Object, so you'll be able to call
java.lang.Object methods on variables typed to the interface.

ie.

public interface MyInterface {}

public class MyClass implements MyInterface
{
	public static void main(String[] args) {
        MyInterface myInterface = new MyClass();

        myInterface.getClass();				<-- javac doesn't complain at all about
this
    	}
}

The best way I can think of achieving what you want is to have Message
extend Cloneable.

public interface Message extends Cloneable
{
	...
}

-- Marc

> -----Original Message-----
> From: advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Pollard,
> Jim
> Sent: Tuesday, January 29, 2002 10:30 AM
> To: advanced-java@xxxxxxxxxxxxxxxx
> Subject: RE: [Advanced-java] CLONE
>
>
> can you use instanceof to tell if something implements the Cloneable
> interface?  can't find anything saying that you can in the spec,
> so i guess
> you cannot.
>
> if not, you can cast the Message to Object, call clone() and then
> catch any
> CloneNotSupportedException.  or add to the interface a method called
> cloneMessage() that the implementing objects must route to their
> own clone()
> methods or else respond with a CloneNotSupportedException.
>
> > -----Original Message-----
> > From: Greg Munt [mailto:greg@xxxxxxxxxxxxxxx]
> > Sent: Tuesday, January 29, 2002 11:04 AM
> > To: advanced-java@xxxxxxxxxxxxxxxx; David Rosenstrauch
> > Subject: Re: [Advanced-java] CLONE
> >
> >
> > Erk.
> >
> > What if the type of the class varies at different times
> > during execution of
> > the program?
> >
> > Try using reflection to see if the clone method is there, or
> > if the object
> > implements Cloneable. Or make Message an extension of Cloneable.
> >
> > ----- Original Message -----
> > From: "David Rosenstrauch" <darose@xxxxxxx>
> > To: <advanced-java@xxxxxxxxxxxxxxxx>
> > Sent: Tuesday, January 29, 2002 4:18 PM
> > Subject: Re: [Advanced-java] CLONE
> >
> >
> > > Do a System.out.println(msg.getClass()) to find out what
> > actual sub-class
> > the object is.  See if that class supports clone.  If it
> > does, then cast msg
> > to the subclass type and call clone on it.
> > >
> > >
> > > DR
> > >
> > >
> > > At 02:52 AM 1/29/02 -0800, diya prakash wrote:
> > > >Hello,
> > > >
> > > >I have what seems like a simple java question!!!!
> > > >
> > > >I have an interface Message and i have something like
> > > >
> > > >Message msg;
> > > >
> > > >I need to clone this msg variable!!!! I dont know how
> > > >to acheive this as msg is not an object.
> > > >
> > > >Kindly help me.
> > > >thank you,
> > > >Ramya
> > >
> > > _______________________________________________
> > > Advanced-java mailing list
> > > Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> > > http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
> > >
> >
> >
> > _______________________________________________
> > Advanced-java mailing list
> > Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> > http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
> >
> _______________________________________________
> Advanced-java mailing list
> Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java