# Function with arg dictionary any not accepting int

**URL:** <https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127>\
**Category:** New to Julia\
**Created:** [November 3, 2018, 10:21pm UTC](https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127 "2018-11-03T22:21:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_McVay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_mcvay/32/4307_2.png) [@Paul\_McVay](https://discourse.julialang.org/u/Paul_McVay)\
**Post date:** [November 3, 2018, 10:21pm UTC](https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127/1 "2018-11-03T22:21:41Z")

</div>

I’m trying to define a function that takes in a dictionary of a string to any

```julia
function test(t::Dict{String, Any})
    @show t
end

```

but when I call it with

```julia
test(Dict("hi" => 1))

```

But I get the following error

```julia
ERROR: MethodError: no method matching test(::Dict{String,Int64})
Closest candidates are:
  test(!Matched::Dict{String,Any}) at none:2
Stacktrace:
 [1] top-level scope at none:0

```

Am I misunderstanding the usage of ‘Any’?

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [November 3, 2018, 10:34pm UTC](https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127/2 "2018-11-03T22:34:50Z")

</div>

In Julia, if `T <: S`, it does not follow that `A{T} <: A{S}` (where `T` and `S` are types, and `A` is a parameterized type). In particular, it is not true that `Dict{String, Int} <: Dict{String, Any}`.

The expression `Dict("hi"=>1)` creates an object of type `Dict{String,Int}`. To force it to create an object of type `Dict{String,Any}`, you need to invoke it as: `Dict{String,Any}("hi" => 1)`.

---

<div class="post-metadata">

**Author:** ![zekeriya.sari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zekeriya.sari/32/13695_2.png) [@zekeriya.sari](https://discourse.julialang.org/u/zekeriya.sari)\
**Post date:** [November 3, 2018, 10:37pm UTC](https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127/3 "2018-11-03T22:37:16Z")

</div>

You can try,

```julia
julia> function test(t::Dict{String, <:Any})
           @show t
       end
test (generic function with 1 method)

julia> test(Dict("hi" => 1))
t = Dict("hi"=>1)
Dict{String,Int64} with 1 entry:
  "hi" => 1

```

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 4, 2018, 7:34am UTC](https://discourse.julialang.org/t/function-with-arg-dictionary-any-not-accepting-int/17127/4 "2018-11-04T07:34:09Z")

</div>

or

```julia
julia> function test(t::Dict{String, T}) where T
           @show t
       end
test (generic function with 2 methods)

julia> test(Dict("hi" => 1))
t = Dict("hi"=>1)
Dict{String,Int64} with 1 entry:
  "hi" => 1

```
