# On type annotations

**URL:** https://discourse.julialang.org/t/on-type-annotations/116305
**Category:** New to Julia
**Created:** [June 27, 2024, 1:13pm UTC](https://discourse.julialang.org/t/on-type-annotations/116305 "2024-06-27T13:13:24Z")
**Posts on this page:** 1
**Showing post:** 29

<div class="post-metadata">

### Author: ![Matthijs\_1971](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Matthijs\_1971](https://discourse.julialang.org/u/Matthijs_1971)
#### Post date: [June 28, 2024, 8:20am UTC](https://discourse.julialang.org/t/on-type-annotations/116305/29 "2024-06-28T08:20:08Z")

</div>

> The second one performs a conversion before assigning to `x` and is equivalent \> to
> 
> ```julia
> x = convert(T, foo())::T
> 
> ```

Perhaps you meant this?

```julia
x::T = convert(T, foo())

```

Afaik, the return value of `convert` is already of type `T` and it does not need to be asserted. The difference is important for the discussion as `x::T` guarantees that `x` will not change type until it goes end of scope.

Indeed, `convert` may be called. It is only called though when there _is_ something to convert. A function annotated with `::S` returning a local variable of type `S` will not induce a call to `convert`. So the performance hit is absent in this case. We expect that developers will not introduce a lot of `convert` methods for other cases.

```julia
julia> import Base.convert

julia> struct S
                  mem::Int64
              end

julia> function convert(::Type{S}, x::Any)::S
                  println("convert(...): Started.")
                  return S(x)
              end
convert (generic function with 196 methods)

julia> function return_right_type(s::S)::S
                  return S(s.mem * s.mem)
              end
return_right_type (generic function with 1 method)

julia> u::S = return_right_type(S(42))
S(1764)

julia> v::S = 5
convert(...): Started.
5

julia> 

```

---

_[View the full topic](https://discourse.julialang.org/t/on-type-annotations/116305)._
