Does Vector{Int64} not inherit from Vector{Number}?

Greetings,

I am just coding up my first little numerical simulation in Julia.

long story short:
Why does this not work?

function func(  x:: Vector{Number} )
    print(x)
end

func([1])

It gives MethodError: no method matching func(::Vector{Int64})

How can I write this method with type annotation saying that the input vector can contain integers, floats or other numbers?

Regards!

Vector{<:Number}

(see, for example, Vector{Int} <: Vector{Real} is false??? · JuliaNotes.jl or this Why [(a = 1, b = 3), (a = 3, b = 4)] isa Vector{NamedTuple} -> false?).

3 Likes

Thanks Imiq,
the first link explained it well.