23.01.2009
Java Snippets: Class.isAssignableFrom() vs. instanceof
For some reason I have to think about the meaning of Class.isAssignableFrom() everytime I use it. That’s because I’m used to the meaning of the instanceof operator:
microwave instanceof Oven
On the Class level, I’d like to write:
Microwave.class.isAssignableTo(Oven.class)
Unfortunately, it’s written the other way round:
Oven.class.isAssignableFrom(Microwave.class)


Thanks! This (and Google) helped me a lot :-)