看板 java 關於我們 聯絡資訊
那就只好使用比較麻煩的方式...... run tw.sub2.test時將會呼叫tw.sub1.test.hello() package tw.sub1; public class test { public void hello() { System.out.println("Hello"); } } ======================================== package tw.sub2; import java.lang.reflect.Method; public class test { public static void main(String[] args) { try { Class<?> cls = Class.forName("tw.sub1.test"); Method method = cls.getMethod("hello") method.invoke(cls.newInstance()); } catch (Exception e) { e.printStackTrace(); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.112.115.88