我有一个间接实现接口(interface)的类(它的父类(super class)或 super 类实现可以实现),我想知道一个类是否实现了接口(interface)。
用编码术语来说:
import java.lang.reflect.Type;
class My implements MyName{
}
public class Tset extends My implements yourName{
public static void main(String[] args) {
Class[] allClassAndInterfaces = Tset.class.getInterfaces();
//but allClassAndInterfaces is not giving me the MyName Interface
//although it gives me YourName Interface
System.out.println(ArrayUtils.toString(lits));
}
}
最佳答案
Class 类中有一个名为 isAssignableFrom 的特定方法,它可以完成您想要的操作。在您的情况下,这应该返回 true:
MyName.class.isAssignableFrom(My.class);
关于java - 反射和接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7662535/