`
jaywee
  • 浏览: 40618 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

clone()方法描述

阅读更多

Object (Java 2 Platform SE 5.0)<!----> <script type="text/javascript"> function windowTitle() { parent.document.title="Object (Java 2 Platform SE 5.0)"; } </script> <noscript></noscript> <script src="/jdk150/H2HHinclude.js"></script>

clone

protected Object
 clone
()
                throws CloneNotSupportedException

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x , the expression:
 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true , but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true , this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone . If a class and all of its superclasses (except Object ) obey this convention, it will be the case that x.clone().getClass() == x.getClass() .

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable , then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable . Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

The class Object does not itself implement the interface Cloneable , so calling the clone method on an object whose class is Object will result in throwing an exception at run time.

 

分享到:
评论

相关推荐

    Java clone方法使用

    详细的描述了Java中 clone方法使用

    jQuery中clone()方法用法实例

    主要介绍了jQuery中clone()方法用法,实例分析了clone()方法的功能、定义及克隆匹配的DOM元素的使用技巧,需要的朋友可以参考下

    ubuntu使用git clone克隆/下载github模型速度慢的解决方案

    描述 使用在linux操作系统上使用git clone下载github上模型速度慢,多数是因为网不好。 提供了两种方法,可以同时使用。 方法:先刷hosts 1. 命令行输入下列代码,找到 github.global.ssl.fastly.Net对应的Address,...

    gh-clone:git克隆一个只有用户名repo的仓库

    gh克隆 ... 请考虑关注该项目的作者 ,并考虑为该项目以显示您的 :red_heart: 和支持。 安装 使用全局安装 $ npm install --global gh-clone CLI用法 克隆一个github仓库: $ gh-clone &lt; repo&gt; [options...描述 -c --cw

    java-数组与方法及面向对象基础

    详细描述了java基础中的数组与方法的应用技术,以及面向对象的过程思想,有助于java初学者的入门学习。

    js-object-clone:深度克隆并与ES5属性描述符和对象可扩展性支持进行比较

    对象克隆ES5的深克隆和比较概要// just ... clone ( src ) ; // shallow copylog ( Object . is ( src , dst ) ) ; // falselog ( Object . equals ( src , dst ) ) ; // truedst . lang . push ( 'javascript' ) ;log

    ball-panic-unity-clone

    恐慌症(Unity Clone) 适合所有年龄段的上瘾游戏,具有简单的游戏机制。 游戏的目的是在收集物品时避免并射出球。 教程: : 控制项按钮描述左键向左移动右按钮向右移拍摄按钮射击从这个游戏中学到了什么? 组织...

    TikTok-Clone-ReactNative:React Native中的TikTok克隆应用程序

    TikTok克隆Copiando ao负责人做TikTok描述:-英语 :-特征 :- 该应用程序使用最新的工具进行移动开发: :atom_symbol: ** React Native **-一个Lib,可让您创建适用于Android和iOS的本机应用TikTok主要布局的所有...

    multisite-clone-duplicator:WordPress插件

    MultiSite Clone Duplicator 为您的网络安装添加了“复制站点”功能。 它允许您将网络中的任何站点克隆到一个新站点:可以复制所有数据、文件、用户和角色。 当您想从同一个模板创建多个站点时,它很有用:不要...

    Git clone

    描述: git clone命令将存储库克隆到新目录中。 将存储库克隆到新创建的目录中,为克隆的存储库中的每个分支创建远程跟踪分支,并从克隆检出的存储库作为当前活动分支的初始分支。 Git支持多协议,ssh://, http://, ...

    twitter_clone

    描述 这是一个模拟Twitter动作的应用程序,除了关注其他用户外,还允许用户注册并创建配置文件 安装 您可以从控制台克隆存储库 从存储库中,您还可以获取zip版本 克隆后,您进入文件夹/ twitter_clone 运行rails s ...

    object-clone:克隆对象支持循环引用

    var clone = require ( '@dmail/object-clone' ) ; var a = { name : 'a' } ; var b = clone ( a ) ; b . name ; // 'a' // of course b != a 它克隆得很深 var a = { list : [ { name : 'first' } ] } ; var...

    AirBnB_clone

    AirBnB_clone 项目描述命令解释器的描述:如何启动它,如何使用它的示例

    Insta-Clone-

    项目3- Insta-Clone Insta-Clone是类似于Instagram照片共享应用程序,但使用Parse作为后端。 花费时间:总共花费5个小时用户故事完成以下必需的功能: 用户可以注册以使用解析身份验证创建新帐户。 用户可以登录和...

    cp-disney-plus-clone:这是DEMO Disney + Clone App

    描述 这是ReactJS Disney Plus Clone,这是由Clever Programmer制作的完美项目。 今天就建造! 前提条件: 在注册Firebase帐户 在在计算机上安装Node JS 下载所有的图像和视频 在观看完整的教程

    Clone-WebOS:Clone-Web OS 是一个 Web 操作系统,您实际上可以在其上执行更多操作,并且专为新的 Clone Cloud 构建

    克隆-WebOS ##描述: ###介绍今天,我们生活在一个由云计算主导的世界中,我们所做的大部分事情都是在别人的服务器上完成的,而我们所知道的桌面已经不复存在。 在网络上运行所有内容的唯一问题是您不知道您的...

    kokoa-clone-2021:可可克隆

    Kokoa Clone 2021更新HTML和CSS非常有趣Lorem ipsum dolor坐在amet,奉献的精英,塞德·杜伊斯莫德临时禁运和劳动大臣阿里夸。 Ut enim ad minim veniam, quis nostrud exercitation ullamco labouris com commodo...

    fruit-ninja-unity-clone

    水果忍者(Unity Clone) 欢迎来到忍者道场。 您的目标:成为切片水果的大师! 有什么比玩最初流行的水果切片手游《水果忍者》更好的方法呢? 教程: : 控制项 按钮 描述 刷卡 切 从这个游戏中学到了什么? ...

Global site tag (gtag.js) - Google Analytics