title: Why toList() creates a List<dynamic> in Dart?
body: <p>I have this method, which compiles with no problems in Dart 2. However at run-time I get the following error </p>
  
  <blockquote>
    <p>type '<code>List&lt;dynamic&gt;</code>' is not a subtype of type '<code>List&lt;ExchangeRate&gt;</code>'</p>
  </blockquote>
  
  <p>As you see in the code I create and return new ExchangeRate objects within <code>.map()</code> and then after that I return a <code>rateEntries.toList()</code> which I expect to be of type <code>List&lt;ExchangeRate&gt;</code>, however it seems to be inferred as type <code>List&lt;dynamic&gt;</code>!!!</p>
  
  <pre><code>@override
  Future&lt;List&lt;ExchangeRate&gt;&gt; getExchangeRatesAt(DateTime time, Currency baseCurrency) async {
    final http.Client client = http.Client();
    final String uri = "some uri ...";
    return await client
      .get(uri)
      .then((response) {
        var jsonEntries = json.decode(response.body) as Map&lt;String, dynamic&gt;;
        var rateJsonEntries = jsonEntries["rates"].entries.toList();
        var rateEntries = rateJsonEntries.map((x) {
          return new ExchangeRate(x.value.toDouble());
        });
        return rateEntries.toList(); // WHY IS IT RETURNING A List&lt;dynamic&gt; here?
      })
      .catchError((e) =&gt; print(e))
      .whenComplete(() =&gt; client.close());
  }
  </code></pre>
  
  <p>However if I cast it specifically to ExchangeRate it would be fine.</p>
  
  <pre><code>    return rateEntries.toList().cast&lt;ExchangeRate&gt;();
  </code></pre>
  
  <p>This casting at the end seems redundant to me, why should I need it?</p>