问题
Is there any method for checking if a one class extends another class? Above code is snippet
File[] fileList = file.listFiles();
if(fileList != null){
for(int i = 0; i < fileList.length; ++i){
ClassName = fileList[i].getName();
if (fileList[i].isFile() && (Class Extends Class2) && ClassName.endsWith(".class")){
String ClassName1 = ClassName.split("\\.")[0];
if (!ClassName1.contains("$")){
if (packages != null){
<Snippet>
}
}
}
}
}
回答1:
Let's say you have classes A
and B
. To determine whether A extends B you can test an instance of A
with instanceof
operator. This is sufficient:
if((new A()) instanceof B)
return true;
来源:https://stackoverflow.com/questions/13537183/java-method-for-checking-if-a-class-extends-another-class