How to check if an object implements an interface?
interface, java, oop
Solution
For an instance
Character.Gorgon gor = new Character.Gorgon();
Then do
gor instanceof Monster
For a Class instance do
Class<?> clazz = Character.Gorgon.class;
Monster.class.isAssignableFrom(clazz);
Problem
How to check if some class implements interface? When having: `Character.Gorgon gor = new Character.Gorgon();` how to check if `gor` implements `Monster` interface? ``` 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"; } } } ``` Is the method `getLevel()` overridden in `Gorgon` correctly, so it can return `level` of new `gor` created?