# Array of type Any vs Union

**URL:** <https://discourse.julialang.org/t/array-of-type-any-vs-union/2788>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 21, 2017, 5:47am UTC](https://discourse.julialang.org/t/array-of-type-any-vs-union/2788 "2017-03-21T05:47:39Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 22, 2017, 4:28am UTC](https://discourse.julialang.org/t/array-of-type-any-vs-union/2788/4 "2017-03-22T04:28:28Z")

</div>

It depends a bit on what you want your function to do. If you want your function to take a vector of all Bs or all Cs, then you can write:

```julia
function f(x::Union{Vector{B}, Vector{C}})
    ...
end

```

(note: you can either have a `Vector{A}` or an `Array{A, 1}` (they’re the same), but not a `Vector{A, 1}` (that’s not a thing)).

If you want to mix and match `B`s and `C`s within the same vector, then you can write:

```julia
function f{T <: A}(x::Vector{T})
    ...
end

```

or, you can use Julia v0.6’s new syntax to write:

```julia
function f(x::Vector{<:A})
    ...
end

```

But note that having a vector that mixes elements of type B and C is going to be slower, since Julia won’t know the exact type of each element of the vector. For more discussion of that situation, check out this thread: [How to make a vector of parametric composite types? - #6 by mkborregaard](https://discourse.julialang.org/t/how-to-make-a-vector-of-parametric-composite-types/2439/6)

---

_[View the full topic](https://discourse.julialang.org/t/array-of-type-any-vs-union/2788)._
