Type check conventions

I recently just discovered how to do type check in Julia, and I was just wondering what the convention is, and what differences are the two methods.

Say I have a variable vec1 of type Vector{<:Number}. If I understand it correctly, this should include vectors that contains of only numbers (integers, complex, floating point, etc, but not strings). Now if I have, more concretely, vec1 is of type Vector{Int64}, then the following will return true:

  • typeof(vec1) <: Vector{<:Number}
  • vec1 isa Vector{<:Number}
  • vec1 isa Vector{Int64}
  • typeof(vec1) == Vector{Int64}

But not the following:

  • typeof(vec1) <: Vector{Number}
  • vec1 isa Vector{Number}
  • typeof(vec1) == Vector{Number}

Which of the correct syntax (ones that return true) is the conventional way of doing the type check? Are they equivalent, or are there any differences? Also, I understand that Vector{Number} is a type consist of any number type (i.e. we can view it as a singleton set), hence when we write Vector{Int64} <: Vector{Number}, it will return false. Is my understanding correct?

Thanks a lot in advance. (:

For the reasons why the last 3 statements are false see


Whether you check with typeof or isa likely won’t matter.

1 Like