Initialize Dict to enable values of different type

What behaviour do you expect exactly?

The third case fails because you define dict_b 3 times.
The last call gives you

julia> dict_b = Dict("f" => "julia")
Dict{String, String} with 1 entry:
  "f" => "julia"

If you fill a Dict{String, String} with non-string values, you will get a MethodError.

You could initialize the Dict with value type Any instead.

julia> dict_b = Dict{String,Any}("f" => "julia")
Dict{String, Any} with 1 entry:
  "f" => "julia"

julia> MyDictFill(dict_b)
Dict{String, Any} with 4 entries:
  "f" => "julia"
  "c" => "str"
  "b" => 1.0
  "a" => true
3 Likes