Can the fields of a Julia type have default values?

@kwdef is what you want. This lets you do:

@kwdef struct MyType
  n::Int64 = 3
end

b = MyType()
b.n == 3
3 Likes