如何检查某个类是否实现接口?当有:
Character.Gorgon gor = new Character.Gorgon();
如何检查是否gor实现Monster接口?
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"; } } }
该方法是否getLevel()被Gorgon正确覆盖,因此可以返回level新gor创建的方法?
getLevel()
Gorgon
level
对于一个实例
然后做
gor instanceof Monster
对于Class实例
Class<?> clazz = Character.Gorgon.class; Monster.class.isAssignableFrom(clazz);