this seems to be a newbie question, In Java, how can I check at compile time if someClass.class is derived from a anotherClass.class or at run-time if at compile time is not possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In code:
If you want to also check that the other class is a real class (and not an interface) add in a call to
isInterface():Example:
Note that
instanceofwon’t work for you because you don’t have instances, only classes.Excerpt from Javadoc for
Class.isAssignableFrom: