标签:class 原型模式 ide object c tst code 获取 string info
public class Cookie implements Cloneable{ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } } public class CookieA extends Cookie{ } public class CookieMachine { private Cookie cookie;//必须可复制,否则makeCookie会抛出异常 public CookieMachine(Cookie cookie){ this.cookie = cookie; } public Cookie makeCookie(){ try { return (Cookie)cookie.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } return null; } } //测试 public class Client { public static void main(String[] args){ CookieMachine cookieMachine = new CookieMachine(new CookieA()); System.out.println(cookieMachine.makeCookie()); System.out.println(cookieMachine.makeCookie()); } }
标签:class 原型模式 ide object c tst code 获取 string info
原文地址:https://www.cnblogs.com/camcay/p/12380415.html