isAssignableFrom() vs. instanceof

In Java, you can check the class of an object using the instanceof operator:

microwave instanceof Oven

When you have a Class object, it would make sense to write:

microwave.getClass().isAssignableTo(Oven.class)

Unfortunately, there is no isAssignableTo. It has to be written the other way round:

Oven.class.isAssignableFrom(microwave.getClass())
Ralf Ebert

Ralf Ebert is an independent software developer, technical writer and trainer. He makes apps for Mac OS X and iOS and builds software solutions for companies using Eclipse RCP and Ruby on Rails. He offers training courses for software developers and writes books and articles about software development.