title: List of mixed types in Dart
body: <p>This <em>compiles</em> in Dart:</p>
  
  <pre class="lang-dart prettyprint-override"><code>var  data = ["abcd", 34, "ef", false];
  int n = data[1];
  print(n*2); // -&gt; 68
  </code></pre>
  
  <p>I thought that list elements should be all of same type. And there is not implicit conversion  from int to string or from bool to string in A):</p>
  
  <pre class="lang-dart prettyprint-override"><code> print(data[1] is int);    // -&gt; true
   print(data[3] is bool);   // -&gt; true
   print(data[1] is String); // -&gt; false
  </code></pre>
  
  <p><strong>EDIT</strong>: as Mattia pointed out the real error in the following lines is not related to swapping elements in the list initializatione but to copy/paste from A) to B) leaving the same index ([1])</p>
  
  <p>And this does <strong><em>not</strong> compile</em> ("abcd" swapped with 34):</p>
  
  <pre class="lang-dart prettyprint-override"><code>var  data = [34, "abcd", "ef", false]; // -&gt; type error
  int n = data[1]; //EDIT: this is a non sense, should be data[0] (no error generated)
  print(n*2);  
  </code></pre>
  
  <p><a href="https://dartpad.dartlang.org/a83ce59618c1323235b1062f00f84282" rel="nofollow noreferrer">Reproducible DartPad</a></p>
  
  <p>Why? Some sort of substitution principle at work?</p>