Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public void test() throws CloneNotSupportedException {
- T t = new T();
- t.setI(10);
- t.setJ(20);
- T cloned = (T)t.clone();
- System.out.println(cloned.getI());
- System.out.println(cloned.getJ());
- }
- public static void main(String[] args) throws CloneNotSupportedException {
- new Test().test();
- }
- class T implements Cloneable {
- private int i = 0;
- private int j = 0;
- public int getI() {
- return i;
- }
- public void setI(int i) {
- this.i = i;
- }
- public int getJ() {
- return j;
- }
- public void setJ(int j) {
- this.j = j;
- }
- @Override
- public Object clone() throws CloneNotSupportedException {
- super.clone();
- T clone = new T();
- clone.setI(getI());
- clone.setJ(getJ());
- return clone;
- }
- }
- }
Add Comment
Please, Sign In to add comment