Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

dart difference between list.of and list.from

// The important difference between the from and of methods are that the
// latter have type annotations and the former do not.
// Since Dart generics are reified and Dart 2 is strongly typed,
// this is key to both ensuring the List/Map is correctly constructed:

List<String> foo = new List.from(<int>[1, 2, 3]); // okay until runtime.
List<String> bar = new List.of(<int>[1, 2, 3]); // analysis error

// And ensuring that the types are inferred correctly:
var foo = new List.from(<int>[1, 2, 3]); // List<dynamic>
var bar = new List.of(<int>[1, 2, 3]); // List<int>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dart #difference
ADD COMMENT
Topic
Name
1+8 =