issubtype(type1, type2)

issubtype(type1, type2)

Return true if and only if all values of type1 are also of type2. Can also be written using the <: infix operator as type1 <: type2.

Examples

julia> issubtype(Float64, Real)
true
julia> issubtype(Int, Number)
true
julia> issubtype(String, AbstractString)
true
julia> issubtype(Number, Int)
false
julia> issubtype(AbstractString, String)
false
julia> issubtype(Any, Int)
true
julia> issubtype(Int, Any)
false

Common mistake example:

julia> issubtype(Float64, Int)
false

In this example, Float64 is not a subtype of Int. It's important to understand that subtyping is not based on numerical compatibility, but rather on the type hierarchy.

See Also

BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: