Jump to content

Enforced immutability: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
imported>Acediast
m (→‎{{header|COBOL}}: Indentation.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
Line 1,527:
 
Note though that if fields are reference types (lists, maps, user-defined classes etc.) even a 'getter' method may enable their internal state to be mutated unless you copy them first.
<syntaxhighlight lang="ecmascriptwren">class A {
construct new(f) {
_f = f // sets field _f to the argument f
Line 1,552:
{{libheader|Wren-trait}}
Since the above entry was written, a ''Const'' class has been added to ''Wren-trait'' which simulates constants to some extent though the values used need themselves to be immutable for this to be water-tight.
<syntaxhighlight lang="ecmascriptwren">import "./trait" for Const
 
Const["six"] = 6
9,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.