# Finding the type used to contruct a parameterized type

**URL:** <https://discourse.julialang.org/t/finding-the-type-used-to-contruct-a-parameterized-type/4967>\
**Category:** General Usage\
**Tags:** type\
**Created:** [July 20, 2017, 6:34am UTC](https://discourse.julialang.org/t/finding-the-type-used-to-contruct-a-parameterized-type/4967 "2017-07-20T06:34:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [July 20, 2017, 6:34am UTC](https://discourse.julialang.org/t/finding-the-type-used-to-contruct-a-parameterized-type/4967/1 "2017-07-20T06:34:44Z")

</div>

Suppose I have a type definition like

```julia
type MyType{T}
    x::Vector{T}
end

```

Now say I have a variable of type `MyType`, but I don’t know what tye is used as `T` for it.  
How can I get the dataype `T`?  
I can’t do `typeof(variable_name.x[1])`, as x may be empty?  
When I do `typeof(var_name.x)`, I gets back something like `Array{Char,1}`. But how to get the `Char` alone?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 20, 2017, 6:54am UTC](https://discourse.julialang.org/t/finding-the-type-used-to-contruct-a-parameterized-type/4967/2 "2017-07-20T06:54:41Z")

</div>

Let the dispatch tell you

`f(::MyType{T}) where T = T`

---

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [July 20, 2017, 7:07am UTC](https://discourse.julialang.org/t/finding-the-type-used-to-contruct-a-parameterized-type/4967/3 "2017-07-20T07:07:53Z")

</div>

This is cool.  
Thanks 🙂
