Make immutable Java object

Your class is not immutable strictly speaking, it is only effectively immutable. To make it immutable, you need to use final: private final String name; private final String age; Although the difference might seem subtle, it can make a significant difference in a multi-threaded context. An immutable class is inherently thread-safe, an effectively immutable class … Read more

Immutable/Mutable Collections in Swift

Arrays Create immutable array First way: let array = NSArray(array: [“First”,”Second”,”Third”]) Second way: let array = [“First”,”Second”,”Third”] Create mutable array var array = [“First”,”Second”,”Third”] Append object to array array.append(“Forth”) Dictionaries Create immutable dictionary let dictionary = [“Item 1”: “description”, “Item 2”: “description”] Create mutable dictionary var dictionary = [“Item 1”: “description”, “Item 2”: “description”] Append … Read more

DeepReadonly Object Typescript

As of TypeScript 2.8, this is now possible and actually an example in the PR for Conditional Types: https://github.com/Microsoft/TypeScript/pull/21316 Also see the notes on type inference for Conditional Types: https://github.com/Microsoft/TypeScript/pull/21496 I modified the example slightly to use the type inference for the readonly array value type because I find (infer R)[] clearer than Array<T[number]> but … Read more