15.17.1 反射
可以使用反射来解决潜在的类型机制。
class Mime{
public void walkAgainstTheWind()}
public void sit(){print(")
}
class SmartDog{
public void speak(){print("Woof")}
}
class CommunicateReflectively{
public static void perform(Object speaker){
Class<?> spkr=speaker.getClass();
Method speak=spkr.getMethod("speak");
speak.invoke(speaker);
}
main(){
CommunicateReflectively.perform(new SmartDog());
}
}