Using invoke() to call more general method

This seems to work:

function Base.convert(::Type{T}, d::Dict{Symbol}) where {T<:C2}
    @info "Converting $T, specific"
    # ...convert, then call other method
    return invoke(convert, Tuple{Type{<:ConfigStruct}, Dict{Symbol}}, T, d)
end

However, I would probably just use constructors. This seems too cute by half:

c1::C1 = Dict(:a => "a")
c2::C2 = Dict(:b => "b")

This looks cleaner and clearer to me:

c1 = C1(a="a")
c2 = C2(b="b")

Regular Julia code rarely needs to invoke invoke.

1 Like