This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A { | |
| const A(this.x) : assert(x != null); | |
| final String x; | |
| String toString() => 'A: $x'; | |
| } | |
| main() { | |
| // Why does this not cause an assertion failure? | |
| A a = A(null); | |
| print(a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Idx { | |
| Idx(this.val); | |
| int val; | |
| } | |
| class S { | |
| final List<int> _list = <int>[]; | |
| add(int value) => _list.add(value); | |
| remove(int index) => _list.removeAt(index); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyImmutable { | |
| final String _x; | |
| const MyImmutable([String x]) | |
| : _x = (x != null) ? x.length > 0 ? x : null : null; | |
| String toString() => 'MyImmutable("$_x")'; | |
| } | |
| void main() { | |
| // These work: | |
| print(const MyImmutable('a')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String fmtCompares(double a, double b) { | |
| return '${a < b}, ${a == b}, ${a > b}, ${a.compareTo(b)}'; | |
| } | |
| void main() { | |
| double nan = 0 / 0; | |
| double negZero = -0.0; | |
| var l = [-1.0, 0.0, 1.0, nan, negZero]; | |
| print(l); | |
| l.sort(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main() { | |
| print( | |
| "code units are 2 bytes in UTF-16. In some cases, one needs a surrogate pair of code units to form a code point. And one might need multiple code points, multiple characters, to form a single grapheme (e.g. an emoji)."); | |
| print(''); | |
| var clapping = '\u{1f44f}'; | |
| print(clapping); | |
| print("codeUnits: ${clapping.codeUnits}."); | |
| print("runes, providing code points, not code units: ${clapping.runes}."); |