clone

Java: super.clone() method and inheritance

走远了吗. 提交于 2019-12-18 11:28:23
问题 I have a quick question regarding the clone() method in Java, used as super.clone() in regard to inheritance - where I call the clone() method in the parent class all the way up from the button. The clone() method is supposed to return a copy of this object, however if I have three classes in an inheritance heirachy and call super.clone() three times, why doesn't the highest class in the inheritance heirachy, just under class Object, get a copy of that class returned? Suppose we have three

SQLAlchemy: Modification of detached object

余生颓废 提交于 2019-12-18 10:35:57
问题 I want to duplicate a model instance (row) in SQLAlchemy using the orm. My first thought was to do this: i = session.query(Model) session.expunge(i) old_id = i.id i.id = None session.add(i) session.flush() print i.id #New ID However, apparently the detached object still "remembers" what id it had, even though I set the id to None while it was detached. Thus, session.flush() tries to execute an UPDATE changing the primary key to null. Is this expected behavior? How can I remove the 'memory' of

Object array clone with subset of properties

左心房为你撑大大i 提交于 2019-12-18 09:16:51
问题 What is the most efficient way in JavaScript to clone an array of uniform objects into one with a subset of properties for each object? UPDATE Would this be the most efficient way to do it or is there a better way? - var source = [ { id: 1, name: 'one', value: 12.34 }, { id: 2, name: 'two', value: 17.05 } ]; // copy just 'id' and 'name', ignore 'value': var dest = source.map(function (obj) { return { id: obj.id, name: obj.name }; }); 回答1: First define a function that clone an object and

Clone pattern for std::shared_ptr in C++

若如初见. 提交于 2019-12-18 09:05:13
问题 Why do you need (in order to make it compile) the intermediate CloneImplementation and std::static_pointer_cast (see Section 3 below) to use the Clone pattern for std::shared_ptr instead of something closer (see Section 2 below) to the use of raw pointers (see Section 1 below)? Because as far as I understand, std::shared_ptr has a generalized copy constructor and a generalized assignment operator? 1. Clone pattern with raw pointers : #include <iostream> struct Base { virtual Base *Clone()

Binding does not have a Clone method, whats an effective way to copy it

久未见 提交于 2019-12-18 05:51:11
问题 I wish to copy a binding, this is so i can set a different source property on it without affecting the original binding. Is this just a case of setting all of the properties on the new binding to be the same as the old? 回答1: if you can't find a method to do this already create an exetension for Binding. public static class BindingExtensions { public static Binding Clone(this Binding binding) { var cloned = new Binding(); //copy properties here return cloned; } } public void doWork() { Binding

How to clone old builder to make a new builder object?

天涯浪子 提交于 2019-12-18 05:26:07
问题 I have a builder class which I am using in one of my project. Let's say I have metricA as builder based on below class. I need to make a new builder metricB based on metricA by cloning metricA so that metricB contains all the values which were already there in metricA . In the constructor of MetricHolder I am initializing some fields (which are not set directly) basis on fields that have been set already. clientTypeOrPayId - I am initializing this field. If payId is present, then I will set

Prototype Pattern in Java - the clone() method

一世执手 提交于 2019-12-18 04:42:15
问题 So, I've been reading on Design Patterns and the Prototype Patterns confuses me. I believe one of the points of using it is avoiding the need for using the new operator. Then I look at this example: http://sourcemaking.com/design_patterns/prototype/java/1 First, Their idea of Prototype implements a clone() method, which is weird. Wikipedia also says I need a pure virtual method clone to be implemented by subclasses (why?). Doesn't Java already provide such a method, doing exactly what we need

Clone or Copy UIViewController or UIView

你离开我真会死。 提交于 2019-12-18 04:39:10
问题 UII need copy, self controller or self.view, i have tried: UIView* viewOfSelf =[self.view copy]; UIViewController* controller = [self copy]; UIView* viewOfSelf =[self.view mutableCopy]; UIViewController* controller = [self mutableCopy]; The error is: -[UIViewController mutableCopyWithZone:]: unrecognized selector sent to instance 0xb803490 -[UIView copyWithZone:]: unrecognized selector sent to instance 0x6e0acb0 回答1: Use - NSData *tempArchiveView = [NSKeyedArchiver archivedDataWithRootObject

Clone a List, Map or Set in Dart

泄露秘密 提交于 2019-12-18 04:32:35
问题 Coming from a Java background: what is the recommended way to "clone" a Dart List , Map and Set ? 回答1: Use of clone() in Java is tricky and questionable 1,2 . Effectively, clone() is a copy constructor and for that, the Dart List , Map and Set types each have a named constructor named .from() that perform a shallow copy; e.g. given these declarations Map<String, int> numMoons, moreMoons; numMoons = const <String,int>{ 'Mars' : 2, 'Jupiter' : 27 }; List<String> planets, morePlanets; you can

Hudson git clone error

南楼画角 提交于 2019-12-18 02:46:12
问题 I have created free-style software project in Hudson. I want to clone a public Git repository: git://github.com/bret/watir.git Build fails with error message: Started by user anonymous Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370 Last Build : #4 Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370 Cloning the remote Git repository