| 28 | |
| 29 | class Communicate { |
| 30 | public static void speak(Object speaker) { |
| 31 | try { |
| 32 | Class<? extends Object> spkr = |
| 33 | speaker.getClass(); |
| 34 | Method talk = |
| 35 | spkr.getMethod("talk", (Class[])null); |
| 36 | talk.invoke(speaker, new Object[]{}); |
| 37 | } catch(NoSuchMethodException e) { |
| 38 | System.out.println( |
| 39 | speaker + " cannot talk"); |
| 40 | } catch(IllegalAccessException e) { |
| 41 | System.out.println( |
| 42 | speaker + " IllegalAccessException"); |
| 43 | } catch(InvocationTargetException e) { |
| 44 | System.out.println( |
| 45 | speaker + " InvocationTargetException"); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | public class Latent { |