Speaker: Stuart Marks
For more see the table of contents
General
- New JEP; candidate state
- JEP-431
- Targeting Java 20
Encounter order
- HashSet does not have. Order depends on hashcode
- Encounter order is insertion order ArrayList, ArrayDeque, LinkedHashSet
- Encounter order is sort order – TreeSet
First and last elements
- get(0), getFirst(), first()
- list.get(list.size()-1), getLast(), last()
Iterating and streaming, forward and reverse
- Iterating – forEach loop – code same for all types to iterate forward
- Iterable tied to forward iteration
- Reverse varies – listIterator(), descendingIterator(), Collections.reverse(), descendingSet()
- Streams use forward iteration as well
- Streaming in reverse order needs spliterator as adapter to order
Sequenced Collection
- Proposed
- SequencedCollection – new subinterface of Collection.
- Includes reversed(), addFirst(), addLast(), getFirst(), getLast(), removeFirst(), removeLast()
- Also SequencedSet, SequencedCollections and SequencedSet
- Includes default methods so doesn’t break existing code
- New methods for sequenced map views
Covariant overrides of reversed()
- Reverses
- View of reversed list, but same list
- Updating reversed view/original updates the other
- Returns same interface you pass in
LinkedHashMap
- Will be able to get reversed views, remove entry from end, etc
- sequencedKeySet(), sequencedValues()
- putFirst(), putLast() – unconditionally put mapping at end regardless of whether addition or replacement
My take
The talk started 15 minutes late due to AV issues. And people waited. That says a lot about people looking forward to this talk! The content was quick but understandable. I like that there was a lot of code shown and run in an IDE without spending time typing. Also, NetBeans which doesn’t show up in as many demos. Despite the late start, it didn’t feel rushed. Ended a few minutes late, but not as late as it started so seems like a win!