OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 typedef void Callback<T>(T x); | |
5 | |
6 class Foo<T> { | |
7 final T finalField; | |
8 final Callback<T> callbackField; | |
9 | |
10 T mutableField; | |
11 Callback<T> mutableCallbackField; | |
12 | |
13 Foo(this.finalField, this.callbackField); | |
14 | |
15 void method(T x) {} | |
16 | |
17 set setter(T x) {} | |
18 | |
19 void withCallback(Callback<T> callback) { | |
20 callback(finalField); | |
21 } | |
22 } | |
23 | |
24 main() { | |
25 Foo<int> fooInt = new Foo<int>(1, (int x) {}); | |
26 | |
27 fooInt.method(3); | |
28 fooInt.setter = 3; | |
29 fooInt.withCallback((int x) {}); | |
30 fooInt.withCallback((num x) {}); | |
31 fooInt.mutableField = 3; | |
32 fooInt.mutableCallbackField = (int x) {}; | |
33 | |
34 Foo<num> fooNum = fooInt; | |
35 fooNum.method(3); | |
36 fooNum.method(2.5); | |
37 fooNum.setter = 3; | |
38 fooNum.setter = 2.5; | |
39 fooNum.withCallback((num x) {}); | |
40 fooNum.mutableField = 3; | |
41 fooNum.mutableField = 2.5; | |
42 fooNum.mutableCallbackField(3); | |
43 fooNum.mutableCallbackField(2.5); | |
44 fooNum.mutableCallbackField = (num x) {}; | |
45 } | |
OLD | NEW |