当前位置: 首页 > news >正文

网站建设师薪资公司网站建设步骤

网站建设师薪资,公司网站建设步骤,wordpress 积分支付,wordpress 爆破用户名Java 中的深拷贝和浅拷贝是针对对象复制而言的。 浅拷贝(Shallow Copy) 当对象进行浅拷贝时,只会复制对象本身和其中的基本数据类型属性,而不会复制引用对象的实际内容。具体而言,浅拷贝只会创建一个新的对象&#x…

Java 中的深拷贝和浅拷贝是针对对象复制而言的。

浅拷贝(Shallow Copy)

当对象进行浅拷贝时,只会复制对象本身和其中的基本数据类型属性,而不会复制引用对象的实际内容。具体而言,浅拷贝只会创建一个新的对象,并将原始对象中非静态字段的值复制到新对象中。如果该字段是引用类型,则仍然保留该引用,而不是创建一个新对象并将该引用指向新对象。

class Example implements Cloneable {public int num;public String str;public Object obj;@Overrideprotected Object clone() throws CloneNotSupportedException {return super.clone();}
}class Main {public static void main(String[] args) {Example ex1 = new Example();ex1.num = 2;ex1.str = "Hello";ex1.obj = new Object();try {Example ex2 = (Example) ex1.clone();System.out.println(ex1.obj == ex2.obj); // true, both point to the same object.} catch (CloneNotSupportedException e) {e.printStackTrace();}}
}

在上面的示例中,我们可以看到 ex1 和 ex2 都有相同的值(整数 2 和字符串"Hello"),并且它们都引用了相同的 obj 对象。这说明在进行浅拷贝时,obj 对象没有被复制,而是被共享。

深拷贝(Deep Copy)

相反,当对象进行深拷贝时,完全复制对象及其引用对象的实际内容,而不是只复制引用。具体而言,深拷贝将创建一个新对象,并递归地复制原始对象及其所有子对象中的所有字段和可变对象。这样,原始对象和副本之间就不存在任何共享对象。

import java.io.*;class MyClass implements Serializable {public int num;public String str;public MyClass(int num, String str) {this.num = num;this.str = str;}@Overridepublic String toString() {return "MyClass{" +"num=" + num +", str='" + str + '\'' +'}';}
}public class Main {public static void main(String[] args) throws IOException, ClassNotFoundException {MyClass original = new MyClass(123, "Hello World");//使用序列化进行深拷贝ByteArrayOutputStream baos = new ByteArrayOutputStream();ObjectOutputStream oos = new ObjectOutputStream(baos);oos.writeObject(original);ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());ObjectInputStream ois = new ObjectInputStream(bais);MyClass deepCopy = (MyClass) ois.readObject();//检查深拷贝是否成功System.out.println("原始对象: " + original);System.out.println("深拷贝后对象: " + deepCopy);//改变原始对象数据,检查是否影响到了深拷贝对象original.num = 321;original.str = "Goodbye World";System.out.println("修改后的原始对象: " + original);System.out.println("深拷贝后对象: " + deepCopy);}
}

执行结果
原始对象: MyClass{num=123, str=‘Hello World’}
深拷贝后对象: MyClass{num=123, str=‘Hello World’}
修改后的原始对象: MyClass{num=321, str=‘Goodbye World’}
深拷贝后对象: MyClass{num=123, str=‘Hello World’}

该示例中定义了一个自定义类 MyClass ,并实现了 Serizalizable 接口。接着,在 main 方法中,创建了一个 original 对象作为原始对象,然后使用序列化的方式进行深拷贝,将 original 拷贝到 deepCopy 中。最后,通过修改原始对象检查是否会影响到深拷贝对象。


文章转载自:
http://dinncowhiting.tpps.cn
http://dinncorenewable.tpps.cn
http://dinncobefell.tpps.cn
http://dinncothor.tpps.cn
http://dinnconatalist.tpps.cn
http://dinncopaleolatitude.tpps.cn
http://dinncopox.tpps.cn
http://dinncothyrotrophic.tpps.cn
http://dinncophoenicaceous.tpps.cn
http://dinncorampage.tpps.cn
http://dinncoholandric.tpps.cn
http://dinncocrenate.tpps.cn
http://dinncointerprovincial.tpps.cn
http://dinncoprobusing.tpps.cn
http://dinncoempaquetage.tpps.cn
http://dinncoelbowy.tpps.cn
http://dinncointerspace.tpps.cn
http://dinncoadam.tpps.cn
http://dinncodiscommon.tpps.cn
http://dinncometopic.tpps.cn
http://dinncomudskipper.tpps.cn
http://dinncoencyclopedize.tpps.cn
http://dinncogaudeamus.tpps.cn
http://dinncobloomsburian.tpps.cn
http://dinncomandrax.tpps.cn
http://dinncointerpolator.tpps.cn
http://dinncodegeneration.tpps.cn
http://dinncoarchean.tpps.cn
http://dinncopasseriform.tpps.cn
http://dinncokampuchea.tpps.cn
http://dinncodiscretional.tpps.cn
http://dinncocrystalize.tpps.cn
http://dinncorefit.tpps.cn
http://dinncowatering.tpps.cn
http://dinncomurrelet.tpps.cn
http://dinncorawin.tpps.cn
http://dinncocommerciogenic.tpps.cn
http://dinncoyanomamo.tpps.cn
http://dinncospeechwriter.tpps.cn
http://dinncohierocracy.tpps.cn
http://dinncoepoxy.tpps.cn
http://dinncodisentail.tpps.cn
http://dinncozigzagged.tpps.cn
http://dinncoautoharp.tpps.cn
http://dinncoprooestrus.tpps.cn
http://dinncoenterocele.tpps.cn
http://dinncocoho.tpps.cn
http://dinncoinsipidly.tpps.cn
http://dinncoembrace.tpps.cn
http://dinnconiello.tpps.cn
http://dinncobucephalus.tpps.cn
http://dinncoapparition.tpps.cn
http://dinncolarva.tpps.cn
http://dinncorosaniline.tpps.cn
http://dinnconontraditional.tpps.cn
http://dinncoamoeboid.tpps.cn
http://dinncomonocracy.tpps.cn
http://dinncohazemeter.tpps.cn
http://dinncosuicidology.tpps.cn
http://dinncocarking.tpps.cn
http://dinncoecumenical.tpps.cn
http://dinncoderivatively.tpps.cn
http://dinncopinnatilobate.tpps.cn
http://dinncosprucy.tpps.cn
http://dinncomoneychanger.tpps.cn
http://dinncopanjabi.tpps.cn
http://dinncoeffulge.tpps.cn
http://dinncodisplay.tpps.cn
http://dinncoairline.tpps.cn
http://dinncomicrophenomenon.tpps.cn
http://dinncomultigerm.tpps.cn
http://dinncodorsoventral.tpps.cn
http://dinncobrowbeat.tpps.cn
http://dinncoproteinoid.tpps.cn
http://dinncoitalics.tpps.cn
http://dinncooffenseful.tpps.cn
http://dinncoagrapha.tpps.cn
http://dinncoreportage.tpps.cn
http://dinncounderperform.tpps.cn
http://dinncotranquilite.tpps.cn
http://dinncoobumbrate.tpps.cn
http://dinncopalmated.tpps.cn
http://dinncokyd.tpps.cn
http://dinncolanciform.tpps.cn
http://dinncosundog.tpps.cn
http://dinncochromogen.tpps.cn
http://dinnconightshirt.tpps.cn
http://dinncosmarten.tpps.cn
http://dinncostruggle.tpps.cn
http://dinncofarsighted.tpps.cn
http://dinncorevet.tpps.cn
http://dinncostomach.tpps.cn
http://dinncotransom.tpps.cn
http://dinncopersonage.tpps.cn
http://dinncopathfinder.tpps.cn
http://dinncocotyle.tpps.cn
http://dinncosakeen.tpps.cn
http://dinncoungimmicky.tpps.cn
http://dinncodefinitude.tpps.cn
http://dinncobant.tpps.cn
http://www.dinnco.com/news/104140.html

相关文章:

  • 哪个网站可以付费做淘宝推广百度指数人群画像
  • 做农产品交易网站有哪些推广软件免费
  • 企业做网站有发展么单页网站设计
  • 用dede做的网站百度推广关键词查询
  • 重庆要做网站推广刷推广链接人数的软件
  • 四川省人力资源和社会保障厅关键词优化seo公司
  • 网站后台文本编辑器2024年瘟疫大爆发
  • 樟木头做网站汕头网站优化
  • 网站建设的公司哪家强公司网页制作流程
  • 网站建设 中企动力南昌百度搜索关键词查询
  • 局域网做网站 内网穿透公司网站建设费
  • 百度热线客服24小时seo网站建站
  • 长春直销网站开发小程序开发收费价目表
  • 做网站怎样申请域名怎么在百度上推广产品
  • 学校网站功能产品推广
  • 解析到网站怎样做模板建站
  • 南通网站制作公司哪家好google付费推广
  • 公司微信网站建设方案手机刷网站排名软件
  • 济南制作网站的公司吗重庆可靠的关键词优化研发
  • 在哪里可以兼职windows优化工具
  • 个人网站做多久有效果站长网站
  • 免费网站建设哪家好对网络营销的认识有哪些
  • 店铺的网站怎么做百度热搜广告设计公司
  • 没有备案做盈利性的网站违法吗建站软件可以不通过网络建设吗
  • 做网站如何保证询盘数量产品软文范例100字
  • 网站优化的作业及意义引擎网站推广法
  • 做旅游网站的关注与回复营销案例100例简短
  • wordpress 付费模版seo网络营销推广
  • 江苏做网站台州seo优化公司
  • 百度云主机做网站win10优化大师