设为首页 加入收藏

TOP

Java里面的对象克隆
2014-11-17 22:09:02 】 浏览:409
Tags:Java 面的 对象 克隆

  java里面的对象克隆:实际存在的对象拷贝几份!


  即将一个实际的对象进行多份拷贝


  Code highlighting produced by Actipro CodeHighlighter (freeware)


  http://www.CodeHighlighter.com/


  package xsocket.server;


  public class Test implements Cloneable {


  private String name;


  public void setName(String arg) {


  this.name = arg;


  }


  public String getName() {


  return this.name;


  }


  public Object clone() throws CloneNotSupportedException {


  return super.clone();


  }


  public static void main(String[] args) throws CloneNotSupportedException {


  Test shepp = new Test();


  shepp.setName("first");


  System.out.println(shepp.getName());


  Test sheppclone = (Test)shepp.clone(); //对象拷出来一份副本


  System.out.println(sheppclone.getName());


  System.out.println("shepp == sheppclose" + (shepp == sheppclone));


  }


  }


  要知道== 表示的是同一份对象。这里面的内存位置是不一样的哦。所以==就不一样了!


  Code highlighting produced by Actipro CodeHighlighter (freeware)


  http://www.CodeHighlighter.com/


  package xsocket.server;


  public class Test implements Cloneable {


  private String name;


  public void setName(String arg) {


  this.name = arg;


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用response.sendRedirect的注意.. 下一篇Jsp利用response.sendRedirect、c..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目