How to specify subtypes of abstract type as type parameters in Julia?

Viewed 267

If I have, say, abstract Component and want a vector of any of its subtype types, how should I specify Vector's type parameter? This naive snippet doesn't work:

type Position<:Component
  x::Real
  y::Real
end

v = Vector{Type{Component}}

push!(v, Position)

ERROR: MethodError: `push!` has no method matching push (::Type{Array{Type{Component},1}}, ::Type{Position})
Closest candidates are:
  push!(::Any, ::Any, ::Any)
  push!(::Any, ::Any, ::Any, ::Any...)
  push!(::Array{Any,1}, ::ANY)
2 Answers
Related