# Why does this method signature turns 2 methods instead of 1?

**URL:** <https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085>\
**Category:** General Usage\
**Created:** [October 19, 2019, 5:45pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085 "2019-10-19T17:45:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [October 19, 2019, 5:45pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/1 "2019-10-19T17:45:35Z")

</div>

```nohighlight
julia> f(x::Int) = "A"
f (generic function with 2 methods)

julia> f(x::Union{Int,Float64}) = "B"
f (generic function with 3 methods)

julia> methods(f,Tuple{Union{Int,Float64}})
# 2 methods for generic function "f":
[1] f(x::Int64) in Main at none:1
[2] f(x::Union{Float64, Int64}) in Main at none:1

```

Thanks

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 19, 2019, 5:59pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/2 "2019-10-19T17:59:58Z")

</div>

The first one is more specific and so takes precedence when the argument is of type Int.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [October 19, 2019, 6:01pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/3 "2019-10-19T18:01:20Z")

</div>

> [@dpsanders](#):
>
> first one is more specific and so takes precedence when the argument is of type Int.

when it comes to dispatch, you are right it is more specific but when it comes to query of methods, the second is more specific?

How can I get the latter one?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 19, 2019, 6:04pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/4 "2019-10-19T18:04:00Z")

</div>

I’m not sure what you mean by “query of methods”. That sounds like dispatch to me.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [October 19, 2019, 6:04pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/5 "2019-10-19T18:04:34Z")

</div>

methods(f,Tuple{Union{Int,Float64}}) → queries the methods of the function f with the signature.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 19, 2019, 6:11pm UTC](https://discourse.julialang.org/t/why-does-this-method-signature-turns-2-methods-instead-of-1/30085/6 "2019-10-19T18:11:27Z")

</div>

methods returns both. I believe the object it returns is an iterator that you can iterate through.
