如何检查某个类是否实现了接口?
当有以下代码:
Character.Gorgon gor = new Character.Gorgon();
如何检查gor
是否实现Monster
接口?
public interface Monster {
public int getLevel();
public int level = 1;
}
public class Character {
public static class Gorgon extends Character implements Monster {
public int level;
@Override
public int getLevel() { return level; }
public Gorgon() {
type = "Gorgon";
}
}
}
Gorgon
中覆盖了getLevel()
方法,以便正确返回新创建的gor
的level
值。