看板 java 關於我們 聯絡資訊
※ 引述《mc18 (無道德事業集團)》之銘言: : 新手來回答新手的問題... : 先不要問"為什麼要這麼用"(主要在於你要用什麼樣的pattern), 有這種example: : (當然, 還會有其他寫法) : package test; : public class A { : private String output; : private A(){}; : public static A createA() throws Exception{ : A a = (A)Class.forName("test.A").newInstance(); : a.setOutput("output"); : return a; : } : public String getOutput() { : return output; : } : public void setOutput(String output) { : this.output = output; : } : } 這裡可以不要使用到 reflection。 public static A createA() { A a = new A(); a.setOutput("output"); return a; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.173.130.237 ※ 編輯: sbrhsieh 來自: 218.173.130.237 (02/10 14:27)