Use class.equals()
:
if (nextMonster.getClass().equals(monster.getClass()))
or, because each class is like a singleton – there’s only one instance of each Class per class loader, and most JVMs only have the one class loader – you can even use an identity comparison:
if (nextMonster.getClass() == monster.getClass())