diff options
| author | woclass <inkydragon@users.noreply.github.com> | 2018-12-03 20:30:45 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-03 20:30:45 +0800 | 
| commit | cd7816a2be62b0dcd2aca181d1aadd68b8e4d5d7 (patch) | |
| tree | f75c300c92d40e29bf59f83775aec019b45e56e7 /dart.html.markdown | |
| parent | 440247a59706603bd980016821ecd6a72a6182d1 (diff) | |
| parent | 1fd955ae6479650b987a54a93b09507bfdf06954 (diff) | |
Merge pull request #1 from adambard/master
Update from Upstream
Diffstat (limited to 'dart.html.markdown')
| -rw-r--r-- | dart.html.markdown | 44 | 
1 files changed, 34 insertions, 10 deletions
diff --git a/dart.html.markdown b/dart.html.markdown index 76857306..e12a4ed5 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -176,23 +176,47 @@ example13() {    match(s2);  } -// Boolean expressions need to resolve to either true or false, as no -// implicit conversions are supported. +// Boolean expressions support implicit conversions and dynamic type  example14() { -  var v = true; -  if (v) { -    print("Example14 value is true"); +  var a = true; +  if (a) { +    print("true, a is $a");    } -  v = null; +  a = null; +  if (a) { +    print("true, a is $a"); +  } else { +    print("false, a is $a"); // runs here +  } + +  // dynamic typed null can be convert to bool +  var b;// b is dynamic type +  b = "abc";    try { -    if (v) { -      // Never runs +    if (b) { +      print("true, b is $b");      } else { -      // Never runs +      print("false, b is $b");      }    } catch (e) { -    print("Example14 null value causes an exception: '${e}'"); +    print("error, b is $b"); // this could be run but got error    } +  b = null; +  if (b) { +    print("true, b is $b"); +  } else { +    print("false, b is $b"); // runs here +  } + +  // statically typed null can not be convert to bool +  var c = "abc"; +  c = null; +  // complie failed +  // if (c) { +  //   print("true, c is $c"); +  // } else { +  //   print("false, c is $c"); +  // }  }  // try/catch/finally and throw are used for exception handling.  | 
