Vector{AbstractString} function parameter won't accept Vector{String} input in julia

夙愿已清 提交于 2019-11-28 01:02:27
StefanKarpinski

You need to write the function signature like this:

function foo{S<:AbstractString}(a::Vector{S})
    # do stuff
end

On Julia 0.6 and newer, it's also possible to write instead

function foo(a::Vector{<:AbstractString})
    # do stuff
end

This is a consequence of parametric type invariance in Julia. See the chapter on types in the manual for more details.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!