Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object copying
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== In other languages === In [[C Sharp (programming language)|C#]], rather than using the interface <code>ICloneable</code>, a generic extension method can be used to create a deep copy using reflection. This has two advantages: First, it provides the flexibility to copy every object without having to specify each property and variable to be copied manually. Second, because the type is generic, the compiler ensures that the destination object and the source object have the same type. In [[Objective-C]], the methods <code>copy</code> and <code>mutableCopy</code> are inherited by all objects and intended for performing copies; the latter is for creating a mutable type of the original object. These methods in turn call the <code>copyWithZone</code> and <code>mutableCopyWithZone</code> methods, respectively, to perform the copying. An object must implement the corresponding <code>copyWithZone</code> method to be copyable. In [[OCaml]], the [[library (computing)|library]] function [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Oo.html#VALcopy Oo.copy] performs shallow copying of an object. In [[Python (programming language)|Python]], the library's copy module provides shallow copy and deep copy of objects through the <code>copy()</code> and <code>deepcopy()</code> functions, respectively.<ref>[https://docs.python.org/library/copy.html Python copy module]</ref> Programmers may define special methods <code>__copy__()</code> and <code>__deepcopy__()</code> in an object to provide custom copying implementation. In [[Ruby (programming language)|Ruby]], all objects inherit two methods for performing shallow copies, [https://docs.ruby-lang.org/en/master/Kernel.html#method-i-clone clone] and [https://docs.ruby-lang.org/en/master/Object.html#method-i-dup dup]. The two methods differ in that <code>clone</code> copies an object's tainted state, frozen state, and any [[singleton pattern|singleton]] methods it may have, whereas <code>dup</code> copies only its tainted state. Deep copies may be achieved by dumping and loading an object's byte stream or YAML serialization.[http://www.ruby-doc.org/docs/ProgrammingRuby/html/classes.html#S5] Alternatively, you can use the deep_dive gem to do a controlled deep copy of your object graphs. [https://rubygems.org/gems/deep_dive] In [[Perl]], nested structures are stored by the use of references, thus a developer can either loop over the entire structure and re-reference the data or use the <code lang='perl'>dclone()</code> function from the module [https://metacpan.org/module/Storable Storable]. In [[Visual Basic for Applications|VBA]], an assignment of variables of type <code>Object</code> is a shallow copy, an assignment for all other types (numeric types, String, user defined types, arrays) is a deep copy. So the keyword <code>Set</code> for an assignment signals a shallow copy and the (optional) keyword <code>Let</code> signals a deep copy. There is no built-in method for deep copies of Objects in VBA.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)