Reputation: 1801
I'm checking Map
class. I would like to know the difference between these two below.
Are they exactly the same? What does Map.of
do?
Map<int, int> m1 = Map.of({1: 1, 2: 2});
Map<int, int> m2 = <int, int>{1: 1, 2: 2};
Upvotes: 0
Views: 399
Reputation: 49
check the this Dart docs
Map.of()
is the same as Map
init
Map.of()
factory Map.of(Map<K, V> other) = LinkedHashMap<K, V>.of;
But my guess is that since Map
initialization is a variable assignment and Map.of()
is a function call, the movement of the assembly is that Map assignment will be faster.
Upvotes: -1