Skip to content

Introduce static MultiValueMap factory methods #32832

Closed
@poutsma

Description

@poutsma

Java 9 introduced static factory methods on the collection interaces, to create immutable collections. We should consider doing the same for MultiValueMap.

There are several open questions to answer:

  • Should multi-value maps returned by these factory methods be immutable, just like the java collections?
  • It seems difficult to create a convenient, unambiguous API that takes keys and values. Consider MultiValueMap.of("foo", "bar", "baz", "qux"). Does the resulting map have two entries (foo->bar and baz->qux)? Or does it have one entry, with three values (foo->[bar, baz, qux])? Without reading the javadoc, you would not know, which makes the method problematic.
  • We could introduce MultiValueMap<K, V> MultiValueMap::of(Map<K, V>), so that you could do MultiValueMap.of(Map.of("foo", "bar").
  • If we also want to support multiple values, we could have MultiValueMap<K, V> MultiValueMap::of(Map<K, List<V>>), which allows MultiValueMap.of(Map.of("foo", List.of("bar", "baz")).
  • If we want to support both of variants (single and multi value), they would have to be named differently because of type erasure. For instance, MultiValueMap<K, V> MultiValueMap::ofSingle(Map<K, V>) and MultiValueMap<K, V> MultiValueMap::ofMulti(Map<K, List<V>>)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions