【发布时间】:2014-10-24 09:18:20
【问题描述】:
我想知道如何在 Java 中复制对象。但我的意思是复制而不实现可克隆接口,而是复制已经存在的对象,其中所有包含其他对象,例如:
JEditorPane editorOryginal = new JEditorPane();
editorOryginal.addFocusListener(new FocusAdapter() {});
editorOryginal.setText("Hello World!");
// ...... other setter and other listeners etc ..
JEditorPane editorCopy = editorOryginal // now i only copy reference to editorOryginal
//but i would like to get copy of object:
JEditorPane editorCopy = editorOryginal.getCopyInstance();
editorOryginal.destroy(); // in JEditorPane this method not exists but we assume existing this method
editorCopy.something(); // here i have my copy but oryginal has been destroyed
【问题讨论】:
-
搜索模型/XxxEditorKit
-
但我不仅需要 editorKit、组件、侦听器等 ..
-
你将从这篇文章中得到必要的解释:en.wikipedia.org/wiki/Object_copy#In_Java
标签: java swing serialization io clone