# Is there a function \`hasspecialization\`?

**URL:** <https://discourse.julialang.org/t/is-there-a-function-hasspecialization/27790>\
**Category:** General Usage\
**Created:** [August 21, 2019, 7:30am UTC](https://discourse.julialang.org/t/is-there-a-function-hasspecialization/27790 "2019-08-21T07:30:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [August 21, 2019, 7:30am UTC](https://discourse.julialang.org/t/is-there-a-function-hasspecialization/27790/1 "2019-08-21T07:30:07Z")

</div>

Is there a strict version of `hasmethod` which only gives true if there is a specialized method with precisely the types I provide in the `Tuple`?

```julia
julia> f(x::Any) = "any"
f (generic function with 1 method)

julia> f(x::Int) = "int"
f (generic function with 2 methods)

julia> hasmethod(f, (Float64,))
true

julia> hasspecialization(f, (Float64,)) # does a function like this exist?
false

```

---

<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 21, 2019, 7:59am UTC](https://discourse.julialang.org/t/is-there-a-function-hasspecialization/27790/2 "2019-08-21T07:59:19Z")

</div>

```julia
julia> f(x::Any) = "any"
f (generic function with 2 methods)

julia> f(x::Int) = "int"
f (generic function with 2 methods)

julia> function hasspecialization(f, args)
           m = which(f, Tuple{Float64})
           return m.sig == Tuple{typeof(f), args...}
       end
hasspecialization (generic function with 1 method)

julia> hasspecialization(f, (Float64,))
false

julia> f(x::Float64) = "float64"
f (generic function with 3 methods)

julia> hasspecialization(f, (Float64,))
true

```

maybe… Not very tested.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [August 21, 2019, 8:49am UTC](https://discourse.julialang.org/t/is-there-a-function-hasspecialization/27790/3 "2019-08-21T08:49:43Z")

</div>

Good enough for my use case. Thanks.
