Proper way to deal with `Vector{Any}` when defining a function

The above is equivalent to the following.

arr = Any[]
push!(arr, "hello")
push!(arr, "world"

To avoid Vector{Any} do

arr = String[]
push!(arr, "hello")
push!(arr, "world"

If you cannot avoid it, the do:

julia> arr = Any[]
Any[]

julia> push!(arr, "hello")
1-element Vector{Any}:
 "hello"

julia> push!(arr, "world")
2-element Vector{Any}:
 "hello"
 "world"

julia> arr = identity.(arr)
2-element Vector{String}:
 "hello"
 "world"
5 Likes