eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Override Java 8 default methods for correctness and efficiency.

Open motlin opened this issue 7 years ago • 3 comments

There are several default methods added to Java 8 collections interfaces that are not overridden in Eclipse Collections. Default methods are often composites that delegate to several other methods. For example, Map.compute() delegates to get(), containsKey(), put(), and remove(). For synchronized/concurrent collections, it may be necessary to override for correctness. For others, it can be more efficient to override (to only call hashcode once, for example).

java.util.Collection#removeIf
java.util.Map#replaceAll
java.util.Map#computeIfAbsent
java.util.Map#computeIfPresent
java.util.Map#compute

List.sort() is especially surprising. We did all this work to rename sort to sortThis to not interfere. Now we're in a state where FastList.asSynchronized().sort() is not atomic.

Completed:

java.util.List#sort (complete - released in 10.0 )
java.util.List#replaceAll (complete - released in 10.0 )
java.util.Map#getOrDefault
java.util.Map#forEach (complete - https://github.com/eclipse/eclipse-collections/pull/1425)
java.util.Map#merge

motlin avatar Apr 08 '18 13:04 motlin

I am working on List#sort and List#replaceAll. For List#sort I am delegating to sortThis.

donraab avatar Aug 12 '18 01:08 donraab

Can this be revived? UnifiedMap.computeIfAbsent(), for example, looks like a simple override and delegation to getIfAbsentPutWithKey

ylexus avatar Sep 01 '22 15:09 ylexus

Thank @ylexus , yes this can be worked on now as next release is a major version.

donraab avatar Sep 01 '22 17:09 donraab