Well, this is not what I exactly meant: http://www.tutorialspoint.com/java/util/collections_unmodifiablelist.htm The class Collection define the method: public static <T> List<T> unmodifiableList(List<? extends T> list) It returns an instance of List. I do not think there is a type UnmodifiedList since it is difficult to type this kind of things. I think monad helps here, but I am not expert. Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. On May 13, 2014, at 11:19 AM, Jan Vrany <jan.vrany@fit.cvut.cz> wrote:
On 13/05/14 15:50, Alexandre Bergel wrote:
I got an interest some years ago, to see if Context-Oriented-Programming would help to have immutable collections.
Apparently, Java supports immutability at runtime (i.e., there is no class ImmutableArrayList as far as I know).
Actually there is. Have a look at java.util.Collections, java.util.Collections.UnmodifiableList/UnmodifiableRandomAccessList in particular. Many libraries define their own immutable collections as far as I have seen.
There's no support for object immutability in the OpenJDK-based JVMs.
Cheers, Jan
So, there is no good design for immutable collections as far as I know. I read something about that on Doug Lea web page.
Cheers, Alexandre