# Do type annotations help Julia determine which method to call?

**URL:** <https://discourse.julialang.org/t/do-type-annotations-help-julia-determine-which-method-to-call/60476>\
**Category:** General Usage\
**Created:** [May 3, 2021, 5:26pm UTC](https://discourse.julialang.org/t/do-type-annotations-help-julia-determine-which-method-to-call/60476 "2021-05-03T17:26:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [May 3, 2021, 5:47pm UTC](https://discourse.julialang.org/t/do-type-annotations-help-julia-determine-which-method-to-call/60476/3 "2021-05-03T17:47:11Z")

</div>

> [@anon60034542](#):
>
> Do type annotations help Julia to determine which method to call?

Not, I suspect, in the way you’re thinking. Values in Julia have types, variables are just labels attached to those values.

With that said, type declarations do have an effect in that they implicitly try to `convert` the right-hand side to the specified type:

```julia
julia> function f()
         x::Float64 = 1
         @show typeof(x)
       end
f (generic function with 1 method)

julia> f()
typeof(x) = Float64

```

What happened here is that the `::Float64` declaration caused Julia to insert a call to `convert(Float64,...)` which does actually produce a _value_ of type `Float64`. You can see this in the `@code_lowered` output:

```julia
julia> @code_lowered f()
CodeInfo(
1 ─ %1 = Base.convert(Main.Float64, 1)
│ x = Core.typeassert(%1, Main.Float64)

```

So the `::Float64` turned into a call to `convert` and a call to `typeassert`. That means that you’ll get the same result here by doing:

```julia
julia> function g()
         x = convert(Float64, 1)
         @show typeof(x)
       end
g (generic function with 1 method)

julia> g()
typeof(x) = Float64

```

or more simply by doing `Float64(1)` or just `1.0`.

So the annotation that you added to a variable here had an effect, but only because the `convert` call that it inserted actually did change the type of the value being assigned to that variable.

This comes back to the same point here: [How does a dictionary store structs? - #2 by rdeits](https://discourse.julialang.org/t/how-does-a-dictionary-store-structs/57866/2) – there is no distinction between “compile-time” and “run-time” types in Julia.

---

_[View the full topic](https://discourse.julialang.org/t/do-type-annotations-help-julia-determine-which-method-to-call/60476)._
