# How to test type equality

**URL:** <https://discourse.julialang.org/t/how-to-test-type-equality/14144>\
**Category:** General Usage\
**Created:** [August 27, 2018, 3:53pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144 "2018-08-27T15:53:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 27, 2018, 3:53pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/1 "2018-08-27T15:53:08Z")

</div>

So the documentation says:

**Be careful with type equality**  
**You generally want to use isa and \<: for testing types, not ==. Checking types for exact equality typically only makes sense when comparing to a known concrete type (e.g. T == Float64), or if you really, really know what you’re doing.**

But: `isa` does not test the equality of the arguments, it tests the _type_ of one of the arguments against the other argument.

So, this comparison of types doesn’t work:

```julia
julia> Float64 isa Float64
false

```

Is that what the intent of using `isa` truly is? If so, how _does_ one test the equality of types?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 27, 2018, 3:56pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/2 "2018-08-27T15:56:20Z")

</div>

I think the documentation is trying to say that you should do:

```julia
1.0 isa Float64

```

or

```julia
typeof(1.0) <: Float64

```

instead of

```julia
typeof(1.0) == Float64

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 27, 2018, 3:59pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/3 "2018-08-27T15:59:27Z")

</div>

Okay, I get that. But what if I have `x = Float64` and I want to check whether `x` is `Float64`?

---

<div class="post-metadata">

**Author:** ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)\
**Post date:** [August 27, 2018, 4:00pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/4 "2018-08-27T16:00:24Z")

</div>

In that context it doesn’t matter that it’s a type — you’re just treating it as a value. So you can use `==`. This is the case the documentation describes as comparing to a known concrete type.

```julia
julia> Float64 == Float64
true

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 27, 2018, 4:09pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/5 "2018-08-27T16:09:02Z")

</div>

Aha, makes sense. Thanks.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 27, 2018, 4:41pm UTC](https://discourse.julialang.org/t/how-to-test-type-equality/14144/6 "2018-08-27T16:41:48Z")

</div>

And just as a note, equality between types is implemented as `==(T1::Type, T2::Type) = T1 <: T2 && T2 <: T1`.
