# Dispatch on type only

**URL:** https://discourse.julialang.org/t/dispatch-on-type-only/66498
**Category:** General Usage
**Tags:** dispatch
**Created:** [August 16, 2021, 3:40pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498 "2021-08-16T15:40:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [August 16, 2021, 3:40pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498/1 "2021-08-16T15:40:30Z")

</div>

Is it possible to dispatch on a type only, not having an instance with a type?  
This works:

```julia
function choose(t::Float64)
    println("choosing t::Float64")
end
function choose(t::Tuple)
    println("choosing t::Tuple")
end

tup = (1,2)
choose(tup)

flt = randn()
choose(flt)

```

For a streaming IO application, I would like to use

> choose(Tuple)

but did not get anywhere.

---

<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 16, 2021, 3:47pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498/2 "2021-08-16T15:47:50Z")

</div>

I believe `Type{T}` is what you’re looking for:

```julia
julia> choose(t::Type{Float64}) = println("choosing t::Float64")
choose (generic function with 1 method)

julia> choose(t::Type{Tuple}) = println("choosing t::Tuple")
choose (generic function with 2 methods)

julia> choose(Float64)
choosing t::Float64

julia> choose(Tuple)
choosing t::Tuple

```

---

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [August 16, 2021, 3:54pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498/3 "2021-08-16T15:54:21Z")

</div>

Yess!  
I take from this that you always pass something, here t is a Type.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [August 16, 2021, 3:57pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498/4 "2021-08-16T15:57:18Z")

</div>

> [@Bardo](#):
>
> I take from this that you always pass something, here t is a Type.

The `t` itself isn’t needed in the signature, you can write just

```julia
choose(::Type{Float64}) = ... 

```

---

<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 16, 2021, 4:17pm UTC](https://discourse.julialang.org/t/dispatch-on-type-only/66498/5 "2021-08-16T16:17:27Z")

</div>

> [@Bardo](#):
>
> I take from this that you always pass something, here t is a Type.

Whether you give it a name in the signature or not, you obviously need to pass _something_ (if you have multiple methods).
