Skip to content

Commit f1c7d8a

Browse files
committed
dart: initializer list in dart
Signed-off-by: Ayush Dubey <ayushdubey70@gmail.com>
1 parent 467a6bf commit f1c7d8a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dart/initializerList.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:math';
2+
3+
class Position {
4+
final int x;
5+
final int y;
6+
final double rad;
7+
8+
//initializer field
9+
Position(int x, int y)
10+
: this.x = x,
11+
this.y = y,
12+
rad = atan2(y, x);
13+
}
14+
15+
main() {
16+
var p = new Position(2, 3);
17+
print('x: ${p.x} y: ${p.y}');
18+
print('rad: ${p.rad}');
19+
}

0 commit comments

Comments
 (0)