clone

Is there a generic method for cloning CLOS objects?

五迷三道 提交于 2019-11-29 07:03:43
I'm looking for a way to clone CLOS objects in a shallow manner, so the created object would be of the same type with the same values in each slot, but a new instance. The closest thing I found is a standard function copy-structure which does this for structures. There is no standard predefined way to copy CLOS objects in general. It is not trivial, if possible at all, to provide a reasonable default copy operation that does the right thing (at least) most of the time for arbitrary objects, since the correct semantics change from class to class and from application to application. The extended

Cloning Objects in VBA?

风格不统一 提交于 2019-11-29 06:54:39
Is there a generic way to clone objects in VBA? So that i could copy x to y instead of copying just the pointer? Dim x As New Class1 Dim y As Class1 x.Color = 1 x.Height = 1 Set y = x y.Color = 2 Debug.Print "x.Color=" & x.Color & ", x.Height=" & x.Height By generic i mean something like Set y = CloneObject(x) rather than having to create my own method for the class copying its properties one by one. OK, here's the beginning of something that illustrates it: Create a class, call it, oh, "Class1": Option Explicit Public prop1 As Long Private DontCloneThis As Variant Public Property Get

Why is Object.clone() native in Java?

十年热恋 提交于 2019-11-29 06:00:42
The clone method on Object , which creates an exact copy of an object, is declared as: protected native Object clone() throws CloneNotSupportedException; Why is it native ? Basically, because the clone() method does something that you cannot do in the Java language: it clones the state the of the object, including its actual class designation. The cloning mechanism in Java is based on each class calling the superclass's clone method, all the way up to Object . Object then uses this "magical" native clone method to duplicate the original object, including its actual class. Think of this: class

Cannot access protected member 'object.MemberwiseClone()'

亡梦爱人 提交于 2019-11-29 05:32:49
I'm trying to use .MemberwiseClone() on a custom class of mine, but it throws up this error: Cannot access protected member 'object.MemberwiseClone()' via a qualifier of type 'BLBGameBase_V2.Enemy'; the qualifier must be of type 'BLBGameBase_V2.GameBase' (or derived from it) What does this mean? Or better yet, how can I clone an Enemy class? Within any class X , you can only call MemberwiseClone (or any other protected method) on an instance of X . (Or a class derived from X ) Since the Enemy class that you're trying to clone doesn't inherit the GameBase class that you're trying to clone it in

How can I clone an Object (deep copy) in Dart?

帅比萌擦擦* 提交于 2019-11-29 05:26:54
Is there a Language supported way make a full (deep) copy of an Object in Dart? Secondary only; are there multiple ways of doing this, and what are the differences? Thanks for clarification! No as far as open issues seems to suggest: http://code.google.com/p/dart/issues/detail?id=3367 And specifically: .. Objects have identity, and you can only pass around references to them. There is no implicit copying. computmaxer Darts built-in collections use a named constructor called "from" to accomplish this. See this post: Clone a List, Map or Set in Dart Map mapA = { 'foo': 'bar' }; Map mapB = new

How to make a deep copy of an InputStream in Java [closed]

吃可爱长大的小学妹 提交于 2019-11-29 04:38:05
I would like to know how to make a deep copy of an InputStream . I know that it can be done with IOUtils packages, but I would like to avoid them if possible. Does anyone know an alternate way? InputStream is abstract and does not expose (neither do its children) internal data objects. So the only way to "deep copy" the InputStream is to create ByteArrayOutputStream and after doing read() on InputStream, write() this data to ByteArrayOutputStream. Then do: newStream = new ByteArrayInputStream(byteArrayOutputStream.toArray()); If you are using mark() on your InputStream then indeed you can not

Java cloning abstract objects

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 03:47:55
I'm wondering if there is any way to do the following. I have an abstract class, Shape , and all its different subclasses and I want to override the clone method. All I want to do in the method is create a new Shape from the toString() of the current one. Obviously I can't do the following because Shape is abstract. Is there another way to do this because overriding clone in every subclass just for a simple name change seems useless. public abstract class Shape { public Shape(String str) { // Create object from string representation } public Shape clone() { // Need new way to do this return

PHP deep clone object

陌路散爱 提交于 2019-11-29 03:19:39
The scenario: fetch an email template from the database, and loop through a list of recipients, personalising the email for each. My email template is returned as a nested object. It might look a little like this: object(stdClass) { ["title"] => "Event Notification" ["sender"] => "notifications@mysite.com" ["content"] => object(stdClass) { ["salutation"] => "Dear %%firstname%%," ["body"] => "Lorem ipsum %%recipient_email%% etc etc..." } } Then I loop through the recipients, passing this $email object to a personalise() function: foreach( $recipients as $recipient ){ $email_body = personalise(

I need to implement C# deep copy constructors with inheritance. What patterns are there to choose from?

一曲冷凌霜 提交于 2019-11-29 03:17:21
问题 I wish to implement a deepcopy of my classes hierarchy in C# public Class ParentObj : ICloneable { protected int myA; public virtual Object Clone () { ParentObj newObj = new ParentObj(); newObj.myA = theObj.MyA; return newObj; } } public Class ChildObj : ParentObj { protected int myB; public override Object Clone ( ) { Parent newObj = this.base.Clone(); newObj.myB = theObj.MyB; return newObj; } } This will not work as when Cloning the Child only a parent is new-ed. In my code some classes

How do I get the seed from a Random in Java?

只谈情不闲聊 提交于 2019-11-29 02:54:22
I am creating a deep clone for some object. The object contains a Random . Is it good practice to retrieve the seed from the Random ? If so, how? There isn't a Random.getSeed() . A Random is intended to be random. Usually you want two Random to produce different numbers rather than to produce the same numbers. You can copy a Random using serialisation/de-serialisation and get the "seed" field using reflection. (But I doubt you should be doing either) Unless the sequence is critical to you, you can take the view that the clone of a Random is itself or any new Random() What you can do is get the