Checking whether a variable is of a supertype

Is there a way to check whether a variable is of a particular supertype. For example, if I initialize

a=1; M = rand(Int64, 3, 4);

can I check whether a is also of type Real and M is also of types AbstractMatrix or Matrix{Real} ? The Julia documentation on types does not provide a command. I am looking for a command say ff such that

ff( a, "Real" )

would return true.

The section you mention basically only mentions isa, which also works for this purpose. You can just:

julia> a=1; M = rand(Int64, 3, 4);

julia> isa(M, AbstractMatrix)
true

julia> isa(a, Integer)
true
2 Likes

Note that M ist not of type Matrix{Real} (which is a concrete type!).

2 Likes

But it is Matrix{<:Real} instead:

julia> a=1; M = rand(Int64, 3, 4);

julia> isa(M, Matrix{<:Real})
true
1 Like

Thank you very much !

Thank you very much for the insight. I also got to learn about the <: notation.