September 2019
Beginner
512 pages
12h 52m
English
If you check out this chapter's list and map examples, you will see we used the [] and {} literals to initialize them. With generics, we can specify a type during the initialization, adding a <elementType>[] prefix for lists and <keyType, elementType>{} for maps.
Take a look at the following example:
main() { var avengerNames = <String>["Hulk", "Captain America"]; var avengerQuotes = <String, String>{ "Captain America": "I can do this all day!", "Spider Man": "Am I an Avenger?", "Hulk": "Smaaaaaash!" };}
Specifying the type of list, in this case, seems to be redundant as the Dart analyzer will infer the string type from the literals we have provided. However, in some cases, this is important, such as when we are ...
Read now
Unlock full access