问题
Given:
Map<WebSocket,String> mListUser;
mListUser= new Map<WebSocket,String>();
From what i understood now to add a new element i should just do:
mListUser[socket]="string";
instead im getting:
type 'String' is not a subtype of type 'int' of 'index'.
What am i doing wrong?
回答1:
Maybe it helps
final test = Map<String, int>();
test.putIfAbsent('58', () => 56);
if key doesn't exist, it will be putted into map.
回答2:
Maybe it helps.
Map<Object,String> map1= new Map<Object,String>();
Collections c = new Collections(); //some random class
map1[new Collections()]="arg1";
map1[c]="arg2";
map1.forEach((k,v)=>print("out: $k $v"));
print(map1[c]);
gets me this output:
out: Instance of 'Collections' arg2
out: Instance of 'Collections' arg1
arg2
来源:https://stackoverflow.com/questions/18175515/dart-language-mapobject-string-how-to-add-new-pair