# Outer constructor method in Julia

**URL:** https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368
**Category:** General Usage
**Created:** [June 17, 2019, 2:20pm UTC](https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368 "2019-06-17T14:20:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [June 17, 2019, 2:20pm UTC](https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368/1 "2019-06-17T14:20:35Z")

</div>

Hi, I’m a bit confused about the following outer constructor method call.

```julia
mutable struct OSMData
        nodes::Dict{Int, OpenStreetMapX.LLA}
        ways::Vector{OpenStreetMapX.Way}
        relations::Vector{OpenStreetMapX.Relation}

        features::Dict{Int, Tuple{String,String}}
        bounds::OpenStreetMapX.Bounds
        
        way_tags::Set{String}
        relation_tags::Set{String}
end
OSMData() = OSMData(Dict{Int, OpenStreetMapX.LLA}(), Vector{OpenStreetMapX.Way}(),
                                       Vector{OpenStreetMapX.Relation}(), Dict{Int, String}(),
                                       Bounds(0.0, 0.0, 0.0, 0.0), Set{String}(), Set{String}())

```

My question is, for the feature attribute of this outer constructor method, the parameter is  
`Dict{Int, String}()`. On the other hand, the definition of the struct OSMData requires that the type of the features attribute is `Dict{Int, Tuple{String,String}}`. Can anyone please let me know why it still works out well in this case.

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [June 17, 2019, 4:14pm UTC](https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368/2 "2019-06-17T16:14:50Z")

</div>

I cannot really tell you why, but there seems to be implicit conversion of empty dicts:

```julia
julia> struct Foo
       x :: Dict{Int,Tuple{String,String}}
       end

julia> Foo(Dict())
Foo(Dict{Int64,Tuple{String,String}}())

julia> Foo(Dict{Int, String}())
Foo(Dict{Int64,Tuple{String,String}}())

julia> Foo(Dict{Int, Any}())
Foo(Dict{Int64,Tuple{String,String}}())

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [June 17, 2019, 4:54pm UTC](https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368/3 "2019-06-17T16:54:57Z")

</div>

Unless an inner constructor is added, there is a default one that calls `convert` to the field type on all the arguments.

---

<div class="post-metadata">

### Author: ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)
#### Post date: [July 6, 2019, 9:30pm UTC](https://discourse.julialang.org/t/outer-constructor-method-in-julia/25368/4 "2019-07-06T21:30:10Z")

</div>

still would be more readable to have `Dict{Int, Tuple{String,String}}()`  
also `Vector{OpenStreetMapX.Relation}()` would look better just as `OpenStreetMapX.Relation[]`  
you can make a pull request and I will merge it
