Search code examples
javaguavaimmutabilitymultimap

Guava Immutable version of LinkedHashMultimap?


I want to create an immutable version of LinkedHashMultiMap. I can roll my own using ImmutableMap and ImmutableList but wondering if there is a way to extend Guava to do it. For example, using Forwarding or Supplier.


Solution

  • It's not clear whether you want a ListMultimap or a SetMultimap, but you almost certainly want ImmutableListMultimap and ImmutableSetMultimap respectively in any event. Like all immutable collections, it'll still preserve insertion order exactly like LinkedHashMultimap.

    Guava's immutable collections are very deliberately not extensible.