| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library object_initializers_test; | 5 library object_initializers_test; |
| 6 | 6 |
| 7 /// Simple program creating an object with field initializers. | 7 /// Simple program creating an object with field initializers. |
| 8 void main() { | 8 void main() { |
| 9 var a = new A('foo1', 'foo2'); | 9 var a = new A('foo1', 'foo2'); |
| 10 print(a.foo1); | 10 print(a.foo1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 A(String foo1, String foo2) | 23 A(String foo1, String foo2) |
| 24 : foo1 = foo1, | 24 : foo1 = foo1, |
| 25 foo2 = foo2; | 25 foo2 = foo2; |
| 26 } | 26 } |
| 27 | 27 |
| 28 class B { | 28 class B { |
| 29 String foo1 = fieldInitializer(1, 'foo1'); | 29 String foo1 = fieldInitializer(1, 'foo1'); |
| 30 String foo2 = fieldInitializer(1, 'foo2'); | 30 String foo2 = fieldInitializer(1, 'foo2'); |
| 31 String foo3 = fieldInitializer(1, 'foo3'); | 31 String foo3 = fieldInitializer(1, 'foo3'); |
| 32 | 32 |
| 33 // TODO: uncomment when support for *this* in initializer list is added. | 33 B(this.foo1, this.foo2) : foo3 = foo2; |
| 34 // B(this.foo1, this.foo2) : foo3 = foo2; | |
| 35 B(this.foo1, this.foo2) : foo3 = fieldInitializer(2, 'foo3'); | |
| 36 } | 34 } |
| 37 | 35 |
| 38 String fieldInitializer(int f, String s) { | 36 String fieldInitializer(int f, String s) { |
| 39 print('$s: $f'); | 37 print('$s: $f'); |
| 40 return '$s: $f'; | 38 return '$s: $f'; |
| 41 } | 39 } |
| OLD | NEW |