reflection - Java - How Can I Check If A Class Is Inheriting From Some Class Or Interface? -
i need check:
public static boolean check(class<?> c, class<?> d) { if (/* c inherits d */) return true; else return false; }
how can ?
and possible without c.newinstance()
?
title wrong @ first time. it's correct.
use isassignablefrom
if(d.isassignablefrom(c)){ // d superclass of c // in other words, c inherits d }
determines if class or interface represented class object either same as, or superclass or superinterface of, class or interface represented specified class parameter. returns true if so; otherwise returns false. if class object represents primitive type, method returns true if specified class parameter class object; otherwise returns false.