java-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java
@Override
    public boolean isAssignableBy(ResolvedType other) {
        if (other instanceof NullType) {
            return !this.isPrimitive();
        }
        // everything is assignable to Object except void
        if (!other.isVoid() && this.getQualifiedName().equals(Object.class.getCanonicalName())) {
            return true;
        }
        // consider boxing
        if (other.isPrimitive()) {
            if (this.getQualifiedName().equals(Object.class.getCanonicalName())) {
                return true;
            } else {
                // Check if 'other' can be boxed to match this type
                if (isCorrespondingBoxingType(other.describe())) return true;

                // Resolve the boxed type and check if it can be assigned via widening reference conversion
                SymbolReference<ResolvedReferenceTypeDeclaration> type = typeSolver.tryToSolveType(other.asPrimitive().getBoxTypeQName());
                return type.getCorrespondingDeclaration().canBeAssignedTo(super.typeDeclaration);
            }
        }
        if (other instanceof LambdaArgumentTypePlaceholder) {
            return this.getTypeDeclaration().hasAnnotation(FunctionalInterface.class.getCanonicalName());
        } else if (other instanceof ReferenceTypeImpl) {
            ReferenceTypeImpl otherRef = (ReferenceTypeImpl) other;
            if (compareConsideringTypeParameters(otherRef)) {
                return true;
            }
            for (ResolvedReferenceType otherAncestor : otherRef.getAllAncestors()) {
                if (compareConsideringTypeParameters(otherAncestor)) {
                    return true;
                }
            }
            return false;
        } else if (other.isTypeVariable()) {
            for (ResolvedTypeParameterDeclaration.Bound bound : other.asTypeVariable().asTypeParameter().getBounds()) {
                if (bound.isExtends()) {
                    if (this.isAssignableBy(bound.getType())) {
                        return true;
                    }
                }
            }
            return false;
        } else if (other.isConstraint()){
            return isAssignableBy(other.asConstraintType().getBound());
        } else if (other.isWildcard()) {
            if (this.getQualifiedName().equals(Object.class.getCanonicalName())) {
                return true;
            } else if (other.asWildcard().isExtends()) {
                return isAssignableBy(other.asWildcard().getBoundedType());
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
@Override
    public boolean isAssignableBy(ResolvedType other) {
        if (other instanceof NullType) {
            return !this.isPrimitive();
        }
        // everything is assignable to Object except void
        if (!other.isVoid() && this.getQualifiedName().equals(Object.class.getCanonicalName())) {
            return true;
        }
        // consider boxing
        if (other.isPrimitive()) {
            if (this.getQualifiedName().equals(Object.class.getCanonicalName())) {
                return true;
            } else {
                // Check if 'other' can be boxed to match this type
                if (isCorrespondingBoxingType(other.describe())) return true;

                // Resolve the boxed type and check if it can be assigned via widening reference conversion
                SymbolReference<ResolvedReferenceTypeDeclaration> type = typeSolver.tryToSolveType(other.asPrimitive().getBoxTypeQName());
                return type.getCorrespondingDeclaration().canBeAssignedTo(super.typeDeclaration);
            }
        }
        if (other instanceof LambdaArgumentTypePlaceholder) {
            return this.getTypeDeclaration().hasAnnotation(FunctionalInterface.class.getCanonicalName());
        } else if (other instanceof ReferenceTypeImpl) {
            ReferenceTypeImpl otherRef = (ReferenceTypeImpl) other;
            if (compareConsideringTypeParameters(otherRef)) {
                return true;
            }
            for (ResolvedReferenceType otherAncestor : otherRef.getAllAncestors()) {
                if (compareConsideringTypeParameters(otherAncestor)) {
                    return true;
                }
            }
            return false;
        } else if (other.isTypeVariable()) {
            for (ResolvedTypeParameterDeclaration.Bound bound : other.asTypeVariable().asTypeParameter().getBounds()) {
                if (bound.isExtends()) {
                    if (this.isAssignableBy(bound.getType())) {
                        return true;
                    }
                }
            }
            return false;
        } else if (other.isConstraint()){
            return isAssignableBy(other.asConstraintType().getBound());
        } else if (other.isWildcard()) {
            if (this.getQualifiedName().equals(Object.class.getCanonicalName())) {
                return true;
            } else if (other.asWildcard().isExtends()) {
                return isAssignableBy(other.asWildcard().getBoundedType());
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
@ Override public boolean isAssignableBy ( ResolvedType other ) { if ( other instanceof NullType ) { return ! this . isPrimitive ( ) ; } // everything is assignable to Object except void if ( ! other . isVoid ( ) && this . getQualifiedName ( ) . equals ( Object . class . getCanonicalName ( ) ) ) { return true ; } // consider boxing if ( other . isPrimitive ( ) ) { if ( this . getQualifiedName ( ) . equals ( Object . class . getCanonicalName ( ) ) ) { return true ; } else { // Check if 'other' can be boxed to match this type if ( isCorrespondingBoxingType ( other . describe ( ) ) ) return true ; // Resolve the boxed type and check if it can be assigned via widening reference conversion SymbolReference < ResolvedReferenceTypeDeclaration > type = typeSolver . tryToSolveType ( other . asPrimitive ( ) . getBoxTypeQName ( ) ) ; return type . getCorrespondingDeclaration ( ) . canBeAssignedTo ( super . typeDeclaration ) ; } } if ( other instanceof LambdaArgumentTypePlaceholder ) { return this . getTypeDeclaration ( ) . hasAnnotation ( FunctionalInterface . class . getCanonicalName ( ) ) ; } else if ( other instanceof ReferenceTypeImpl ) { ReferenceTypeImpl otherRef = ( ReferenceTypeImpl ) other ; if ( compareConsideringTypeParameters ( otherRef ) ) { return true ; } for ( ResolvedReferenceType otherAncestor : otherRef . getAllAncestors ( ) ) { if ( compareConsideringTypeParameters ( otherAncestor ) ) { return true ; } } return false ; } else if ( other . isTypeVariable ( ) ) { for ( ResolvedTypeParameterDeclaration . Bound bound : other . asTypeVariable ( ) . asTypeParameter ( ) . getBounds ( ) ) { if ( bound . isExtends ( ) ) { if ( this . isAssignableBy ( bound . getType ( ) ) ) { return true ; } } } return false ; } else if ( other . isConstraint ( ) ) { return isAssignableBy ( other . asConstraintType ( ) . getBound ( ) ) ; } else if ( other . isWildcard ( ) ) { if ( this . getQualifiedName ( ) . equals ( Object . class . getCanonicalName ( ) ) ) { return true ; } else if ( other . asWildcard ( ) . isExtends ( ) ) { return isAssignableBy ( other . asWildcard ( ) . getBoundedType ( ) ) ; } else { return false ; } } else { return false ; } }
This method checks if ThisType t = new OtherType() would compile.
This method checks if ThisType t = new OtherType () would compile .