public static void main(String[] args){ TempImpl t1 = new TempImpl("temp1"); try { Method t1Talk = t1.getClass().getMethod("Talk", new Class[0]) ; t1Talk.invoke(t1, null); } catch (NoSuchMethodException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } catch (IllegalAccessException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } catch (InvocationTargetException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } try { System.in.read(); } catch (IOException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } } |
public static void main(String[] args){ TempImpl t1 = new TempImpl("temp1"); TempImpl t2 = new TempImpl("temp2"); Temp2 temp2 = new Temp2(); try { Method t1Talk = t1.getClass().getMethod("Talk", new Class[0]) ; Method t2Talk = t2.getClass().getMethod("Talk", new Class[0]) ; t1Talk.invoke(t2, null); t2Talk.invoke(t1, null); if(t1Talk.equals(t2Talk)){ System.out.println("equals"); } else{ System.out.println("not equals"); } if(t1Talk==t2Talk){ System.out.println("ref equals"); } else{ System.out.println("ref not equals"); } t2Talk.invoke(temp2, null); } catch (NoSuchMethodException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } catch (IllegalAccessException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } catch (InvocationTargetException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } try { System.in.read(); } catch (IOException e) { e.printStackTrace();//To change body of catch statement use File | Settings | File Templates. } } |
[1] [2] 下一页