小编Kri*_*son的帖子

Julia中的字段和属性之间有什么区别?

Julia具有setter函数setproperty!setfield!getter函数getpropertygetfield并且在结构上运行。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

22
推荐指数
1
解决办法
626
查看次数

标签 统计

julia ×1