public static boolean hasImplemented(Object o, String interfaceName) {
Class[] interfaces = o.getClass().getInterfaces();
for(int i = 0; i < interfaces.length; i++)
if(interfaces[i].getName().equals(interfaceName)) return true;
return false;
}
public static void main(String[] args) {
String s = "hello, world";
Test f = new Test();
System.out.println(hasImplemented(s, "java.lang.Comparable")); //true
System.out.println(hasImplemented(f, "java.io.Serializable")); //true
}
}