Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • A ReadableFoo, a ReadOnlyFoo, and an ImmutableFoo should make different promises; all should promise that items may be read out; the second should additionally promise that it cannot be typecast or otherwise manipulated to yield a reference which could be used to mutate the collection; the third should promise that no reference that could manipulate the collection could possibly exist. All three promises have independent uses, and would have value as separate types. As an alternative to using instanceof tests, one could have virtual methods AsMutable, AsReadOnly, and AsImmutable,... Commented Jan 18, 2014 at 18:10
  • ...which would return either this, a wrapper, or a new object, as appropriate. It may also be helpful to have AsNewImmutable, although that wouldn't need to be virtual (since all types should implement it as return new MutableFoo(this);). Commented Jan 18, 2014 at 18:12