Slide 9
Slide 9 text
Three ways to Sunday
• There are three ways to create any immutable collection
• If the items are known a priori, use the .of factory method
ImmutableList.of 3, 1, 4, 1, 5, 9 # [3, 1, 4, 1, 5, 9]
ImmutableSet.of 3, 1, 4, 1, 5, 9 # [3, 1, 4, 5, 9]
ImmutableSortedSet.of 'foo', 'bar', 'baz'
# [bar, baz, foo]
ImmutableMap.of :foo, 3, :bar, 1, :baz, 4
# {foo=3, bar=1, baz=4}
ImmutableMap.of :foo, 3, :foo, 1 # IllegalArgumentException
• For unsorted collections, the insertion order is used
o Ordering not unlike LinkedHashMap/LinkedHashSet