'Fill Map<String, Object> with two strings
I want to fill my Map with two strings. For my Map I have to use <String, Object>.
Using <String, String> would instantly solve my problem, but that is not possible.
What do I need to change to make it work?:
Map<String, Object> myMap= [:]
myMap."foo" = "Bar"
Solution 1:[1]
What do I need to change to make it work?:
Map<String, Object> myMap= [:]
myMap."foo" = "Bar"
Nothing really. That code is perfectly valid. You could also do this:
Map<String, Object> myMap= [:]
myMap.foo = 'Bar'
Or this:
Map<String, Object> myMap= [foo: 'Bar']
And all of those will work if you change Map<String, Object>
to Map<String, String>
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeff Scott Brown |