Type Hierarchy for Containers Values confusing

Viewed 30

Integer is a super type of Int64. Hence, the following should work

function foo(a::Integer)
    return 42
end

foo(2)

and indeed it does:

42

The method used is

@which foo(2)
foo(a::Integer)

But why then is the same not possible for an array/vector?

function bar(a::Vector{Integer})
    return 42
end

bar([2, 3])
ERROR: MethodError: no method matching bar(::Array{Int64,1})
0 Answers
Related