# Dispatch on Type

**URL:** <https://discourse.julialang.org/t/dispatch-on-type/87680>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 23, 2022, 1:31am UTC](https://discourse.julialang.org/t/dispatch-on-type/87680 "2022-09-23T01:31:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [September 23, 2022, 1:31am UTC](https://discourse.julialang.org/t/dispatch-on-type/87680/1 "2022-09-23T01:31:29Z")

</div>

I am hoping to create a function that will dispatch on the type I put in. Basically the function will look at the fields of the structure and do things based on the number of fields and the fieldnames. As a MWE I would like to be able to print the type. I show a few tries here

```julia
julia> Complex <: Number
true

julia> function foo(type::Number)
           println(type)
       end
foo (generic function with 2 methods)

julia> foo(Complex)
ERROR: MethodError: no method matching foo(::Type{Complex})
Closest candidates are:
  foo(::Real) at REPL[9]:1
  foo(::Number) at REPL[11]:1
Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

julia> function foo(type::T) where T<:Number
           println(type)
       end
foo (generic function with 2 methods)

julia> foo(ComplexF64)
ERROR: MethodError: no method matching foo(::Type{ComplexF64})
Closest candidates are:
  foo(::Real) at REPL[2]:1
  foo(::T) where T<:Number at REPL[5]:1
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

```

Is this possible? How would I do it?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 23, 2022, 1:38am UTC](https://discourse.julialang.org/t/dispatch-on-type/87680/2 "2022-09-23T01:38:25Z")

</div>

You want `foo(type::Type{T}) where T<:Number`
