Modifying vector in an immutable

When an immutable has a Vector field, is it allowed to modify that using ! functions (like these)? My understanding is that even if the underlying memory is remapped (eg because the vector grows or shrinks too much), it is still the “same” vector, so it is OK. MWE:

immutable Foo
    v::Vector
end
foo = Foo([])
push!(foo.v, 1)
1 Like

It is still the same julia object. This is perfectly fine.

1 Like

Note that you (almost) always want to strictly type fields in a type definition:

immutable Foo
    v::Vector{Float64}
end

or parametrically:

immutable Foo{T}
    v::Vector{T}
end

Definitely — I was just keeping the example minimal.