# How to get the parameter of a parameteric type wihtout looking at the fields

**URL:** <https://discourse.julialang.org/t/how-to-get-the-parameter-of-a-parameteric-type-wihtout-looking-at-the-fields/87967>\
**Category:** General Usage\
**Created:** [September 29, 2022, 8:13am UTC](https://discourse.julialang.org/t/how-to-get-the-parameter-of-a-parameteric-type-wihtout-looking-at-the-fields/87967 "2022-09-29T08:13:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [September 29, 2022, 8:13am UTC](https://discourse.julialang.org/t/how-to-get-the-parameter-of-a-parameteric-type-wihtout-looking-at-the-fields/87967/1 "2022-09-29T08:13:23Z")

</div>

I want to retrieve the parameter of a parametric type of an object.  
There are already several discussion on this, [here](https://discourse.julialang.org/t/get-type-of-field-in-parametric-type/8210) or on [SO](https://stackoverflow.com/questions/35759794/get-parameters-of-a-parametric-type), but I don’t want to look up at the object fields, as this would be application-specific, it is deep in my real case and it could change in the future.

So far this works:

```julia
julia> struct Foo{T}
           x::T
       end

julia> a = Foo(2.2)

Foo{Float64}(2.2)

julia> b = Foo(2)
Foo{Int64}(2)

julia> get_parametric_type(a::Foo{T}) where { T }= return T
get_parametric_type (generic function with 1 method)

julia> get_parametric_type(b)
Int64

```

But how do I generalise the function to all parametric types with a single parameter ? For example

```julia
julia> struct Goo{T}
           y::Int64
           z::T
       end

julia> c = Goo(1,1)
Goo{Int64}(1, 1)

julia> get_parameteric_type(c)
ERROR: UndefVarError: get_parameteric_type not defined
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

```

(and as we are here, not really need now, but could be useful, how to get all the parameters of an object `foo::XXX{T1,T2,T3}` → `(T1,T2,T3)` ? )

EDIT: I see that the answer on the old thread on SO still works:

`get_parameteric_types(obj) = typeof(obj).parameters`

but it feels a bit a hacky, as it uses internals of Julia, still l don’t think that this is going to change soon 🙂
