News for hackers. Stuff that matters.
Re:Immutable annotations for Java by _asummers on Sunday July 12, 2015 @02:40PM (#9874420)
Fair point, you're absolutely correct. Admittedly I haven't given this a TON of thought, because it seems like something that can't be added anymore. Maybe the interfaces should be siblings, but since Java doesn't have a disjoint type, you might run into problems if something says it implements both MutableList and ImmutableList. Not sure if Java's type system is strong enough to deal with this problem.
Re:Immutable annotations for Java by kilink on Sunday July 12, 2015 @04:18PM (#9874800)
I think the Map interface should have been composed of two interfaces, ReadableMap and WriteableMap. Then APIs could return ReadableMap, which would lack the mutator methods altogether.
Re:Immutable annotations for Java by dorgo on Monday July 20, 2015 @03:29AM (#9914476)
Then a Map would be a ReadableMap, but a ReadableMap wouldn't be a Map. If a method expects a Map, you would't be able to put a ReadableMap (or a WriteableMap) into it. My solution so far is to avoid to return a map or to expect a map as argument.