Closed Thihup closed 2 years ago
Currently, the spec only shows examples of the map literals using Strings:
2.2.3. Map Construction Construct an instance of java.util.Map<Object,Object>. 2.2.3.1. Syntax Map := '{' MapEntries '}' MapEntries := (MapEntry (',' MapEntry)* )? MapEntry := expression ':' expression 2.2.3.2. Example {"one":1, "two":2, "three":3}
However, the MapEntry shows that the key is an expression, so it could mean that a variable could be used as a key. Is that right?
Correct. An expression can be used for the key and/or the value when defining a Map.
Currently, the spec only shows examples of the map literals using Strings:
However, the MapEntry shows that the key is an expression, so it could mean that a variable could be used as a key. Is that right?