Skip to content

Override Java 8 default methods for correctness and efficiency. #500

@motlin

Description

@motlin

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions