public boolean isSubtype(ReferenceType type,ReferenceType possibleSupertype) throws ClassNotFoundException {
  if (type.equals(possibleSupertype)) {
    return true;
  }
  if (possibleSupertype.equals(Type.OBJECT)) {
    return true;
  }
  if (type.equals(Type.OBJECT)) {
    return false;
  }
  boolean typeIsObjectType=(type instanceof ObjectType);
  boolean possibleSupertypeIsObjectType=(possibleSupertype instanceof ObjectType);
  if (typeIsObjectType && possibleSupertypeIsObjectType) {
    return isSubtype((ObjectType)type,(ObjectType)possibleSupertype);
  }
  boolean typeIsArrayType=(type instanceof ArrayType);
  boolean possibleSupertypeIsArrayType=(possibleSupertype instanceof ArrayType);
  if (typeIsArrayType) {
    if (possibleSupertype.equals(SERIALIZABLE) || possibleSupertype.equals(CLONEABLE)) {
      return true;
    }
    if (!possibleSupertypeIsArrayType) {
      return false;
    }
    ArrayType typeAsArrayType=(ArrayType)type;
    ArrayType possibleSupertypeAsArrayType=(ArrayType)possibleSupertype;
    if (typeAsArrayType.getDimensions() < possibleSupertypeAsArrayType.getDimensions()) {
      return false;
    }
    Type possibleSupertypeBasicType=possibleSupertypeAsArrayType.getBasicType();
    if (!(possibleSupertypeBasicType instanceof ObjectType)) {
      return false;
    }
    Type typeBasicType=typeAsArrayType.getBasicType();
    if (typeAsArrayType.getDimensions() > possibleSupertypeAsArrayType.getDimensions()) {
      return isSubtype(new ArrayType(typeBasicType,typeAsArrayType.getDimensions() - possibleSupertypeAsArrayType.getDimensions()),(ObjectType)possibleSupertypeBasicType);
    }
    if (!(typeBasicType instanceof ObjectType)) {
      return false;
    }
    return isSubtype((ObjectType)typeBasicType,(ObjectType)possibleSupertypeBasicType);
  }
  return false;
}

public boolean isSubtype ( ReferenceType type , ReferenceType possibleSupertype ) throws ClassNotFoundException { if ( type . equals ( possibleSupertype ) ) { return true ; } if ( possibleSupertype . equals ( Type . OBJECT ) ) { return true ; } if ( type . equals ( Type . OBJECT ) ) { return false ; } boolean typeIsObjectType = ( type instanceof ObjectType ) ; boolean possibleSupertypeIsObjectType = ( possibleSupertype instanceof ObjectType ) ; if ( typeIsObjectType && possibleSupertypeIsObjectType ) { return isSubtype ( ( ObjectType ) type , ( ObjectType ) possibleSupertype ) ; } boolean typeIsArrayType = ( type instanceof ArrayType ) ; boolean possibleSupertypeIsArrayType = ( possibleSupertype instanceof ArrayType ) ; if ( typeIsArrayType ) { if ( possibleSupertype . equals ( SERIALIZABLE ) || possibleSupertype . equals ( CLONEABLE ) ) { return true ; } if ( ! possibleSupertypeIsArrayType ) { return false ; } ArrayType typeAsArrayType = ( ArrayType ) type ; ArrayType possibleSupertypeAsArrayType = ( ArrayType ) possibleSupertype ; if ( typeAsArrayType . getDimensions ( ) < possibleSupertypeAsArrayType . getDimensions ( ) ) { return false ; } Type possibleSupertypeBasicType = possibleSupertypeAsArrayType . getBasicType ( ) ; if ( ! ( possibleSupertypeBasicType instanceof ObjectType ) ) { return false ; } Type typeBasicType = typeAsArrayType . getBasicType ( ) ; if ( typeAsArrayType . getDimensions ( ) > possibleSupertypeAsArrayType . getDimensions ( ) ) { return isSubtype ( new ArrayType ( typeBasicType , typeAsArrayType . getDimensions ( ) - possibleSupertypeAsArrayType . getDimensions ( ) ) , ( ObjectType ) possibleSupertypeBasicType ) ; } if ( ! ( typeBasicType instanceof ObjectType ) ) { return false ; } return isSubtype ( ( ObjectType ) typeBasicType , ( ObjectType ) possibleSupertypeBasicType ) ; } return false ; }
determine whether or not a given referencetype is a subtype of another . throws classnotfoundexception if the question cannot be answered definitively due to a missing class .
