Julia具有setter函数setproperty!和setfield!getter函数getproperty,getfield并且在结构上运行。Julia中的属性和字段之间有什么区别?
例如,以下内容似乎表明它们执行相同的操作:
julia> mutable struct S
a
end
julia> s = S(2)
S(2)
julia> getfield(s, :a)
2
julia> getproperty(s, :a)
2
julia> setfield!(s, :a, 3)
3
julia> s
S(3)
julia> setproperty!(s, :a, 4)
4
julia> s
S(4)
Run Code Online (Sandbox Code Playgroud) julia ×1