I'm using Javassist in a code generator I'm writing. It's pretty nice, but I've run into a problem.
When I'm looking at the CtField in question, I want to determine if it's a collection or not. This is pretty trivial with normal reflectio开发者_如何学JAVAn:
Collection.class.isAssignableFrom(...)
But I haven't quite figured out how to get that same effect from Javassist. This is pretty basic stuff, so I must just be missing it.
I don't think Javassist has anything similar, but walking the interface hierarchy is fairly easy.
public boolean isImplementor(final CtClass interfaceClass,
                             final CtClass clazz) throws NotFoundException {
    return isImplementor(interfaceClass, clazz.getInterfaces())
        || isImplementor(interfaceClass, clazz.getSuperclass());
}
private boolean isImplementor(final CtClass interfaceClass,
                              final CtClass[] interfaces) throws NotFoundException {
    for (final CtClass intf : interfaces) {
        if (intf == interfaceClass || isImplementor(interfaceClass, 
                                                    intf.getInterfaces())) {
            return true;
        }
    }
    return false;
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论