# Generic Structs in Dicts

**URL:** <https://discourse.julialang.org/t/generic-structs-in-dicts/77569>\
**Category:** General Usage\
**Tags:** dictionary, struct\
**Created:** [March 8, 2022, 9:14am UTC](https://discourse.julialang.org/t/generic-structs-in-dicts/77569 "2022-03-08T09:14:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [March 8, 2022, 9:14am UTC](https://discourse.julialang.org/t/generic-structs-in-dicts/77569/1 "2022-03-08T09:14:40Z")

</div>

Hi all 🙂

Does anyone know why the following doesn’t work?

```julia
julia> struct A{T} a::T end

julia> Dict{<:A,Int}
Dict{<:A, Int64}

julia> Dict{<:A,Int}()
ERROR: MethodError: no method matching (Dict{<:A, Int64})()
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

```

Cheers

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 8, 2022, 10:12am UTC](https://discourse.julialang.org/t/generic-structs-in-dicts/77569/2 "2022-03-08T10:12:00Z")

</div>

Looks like it needs an actual type

```julia
julia> Dict{<:Number, Int}()
ERROR: MethodError: no method matching (Dict{var"#s1", Int64} where var"#s1"<:Number)()

julia> Dict{Number, Int}()
Dict{Number, Int64}()

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [March 8, 2022, 10:15am UTC](https://discourse.julialang.org/t/generic-structs-in-dicts/77569/3 "2022-03-08T10:15:11Z")

</div>

The shorthand `<:A` in

```julia
Dict{<:A,Int}()

```

translates to

```julia
(Dict{T,Int} where T<:A)()

```

which does not have a constructor defined as the error points out.

But what you are after anyway is

```julia
Dict{T where T<:A, Int}()

```

which works.
