public static boolean isSubTypeOf ( Class parentClass , Class childClass ) { try { // Check that the child class can be cast as a sub-type of the parent. childClass . asSubclass ( parentClass ) ; return true ; } catch ( ClassCastException e ) { // Exception noted so can be ignored. e = null ; return false ; } }
Checks that the child class is the same type or a sub - type of the parent class .