# Checking whether a variable is of a supertype

**URL:** <https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563>\
**Category:** New to Julia\
**Created:** [February 16, 2022, 2:08pm UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563 "2022-02-16T14:08:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [February 16, 2022, 2:08pm UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/1 "2022-02-16T14:08:18Z")

</div>

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

```julia
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](http://web.mit.edu/julia_v0.6.2/julia/share/doc/julia/html/en/manual/types.html#Operations-on-Types-1) does not provide a command. I am looking for a command say `ff` such that

```julia
ff( a, "Real" )

```

would return `true`.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 16, 2022, 2:16pm UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/2 "2022-02-16T14:16:30Z")

</div>

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

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

julia> isa(M, AbstractMatrix)
true

julia> isa(a, Integer)
true

```

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [February 16, 2022, 2:21pm UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/3 "2022-02-16T14:21:47Z")

</div>

> [@iamsuddhasattwa](#):
>
> M is also of types `AbstractMatrix` or `Matrix{Real}`

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

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 16, 2022, 2:29pm UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/4 "2022-02-16T14:29:05Z")

</div>

But it is `Matrix{<:Real}` instead:

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

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

```

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [February 17, 2022, 2:54am UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/5 "2022-02-17T02:54:00Z")

</div>

Thank you very much !

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [February 17, 2022, 2:54am UTC](https://discourse.julialang.org/t/checking-whether-a-variable-is-of-a-supertype/76563/6 "2022-02-17T02:54:36Z")

</div>

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