Zig structs vs Java classes

in Zig struct fields are always public and immutable after initialization

No, structs fields are mutable from a language perspective, there may be other reasons why a field can’t be mutated, for example the struct itself may be in a const, and the memory of that const may reside in the read only section of the executable, but these things are orthogonal reasons that may make it more difficult or impossible, to mutate the field of a struct.


Parameters however are immutable, Pass by value Parameters:

Structs, unions, and arrays can sometimes be more efficiently passed as a reference, since a copy could be arbitrarily expensive depending on the size. When these types are passed as parameters, Zig may choose to copy and pass by value, or pass by reference, whichever way Zig decides will be faster. This is made possible, in part, by the fact that parameters are immutable.