OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class Override { | 7 class Override { |
8 int hash; | 8 int hash; |
9 int get superHash => super.hashCode; | 9 int get superHash => super.hashCode; |
10 int get hashCode => hash; | 10 int get hashCode => hash; |
11 | 11 |
12 int foo() => hash; // Just some function that can be closurized. | 12 int foo() => hash; // Just some function that can be closurized. |
13 | 13 |
14 bool operator==(Object other) => | 14 bool operator==(Object other) => |
15 other is Override && (other as Override).hash == hash; | 15 other is Override && (other as Override).hash == hash; |
16 } | 16 } |
17 | 17 |
18 int bar() => 42; // Some global function. | 18 int bar() => 42; // Some global function. |
19 | 19 |
20 main() { | 20 main() { |
21 var o = new Object(); | 21 var o = new Object(); |
22 var hash = o.hashCode; | 22 var hash = o.hashCode; |
(...skipping 16 matching lines...) Expand all Loading... |
39 } | 39 } |
40 // These do, or might do, but we can still use hashCodeOf and get the same | 40 // These do, or might do, but we can still use hashCodeOf and get the same |
41 // result each time. | 41 // result each time. |
42 samples = ["string", "", (x) => 42, c.foo, bar]; | 42 samples = ["string", "", (x) => 42, c.foo, bar]; |
43 for (var v in samples) { | 43 for (var v in samples) { |
44 print(v); | 44 print(v); |
45 Expect.equals(v.hashCode, v.hashCode); | 45 Expect.equals(v.hashCode, v.hashCode); |
46 Expect.equals(identityHashCode(v), identityHashCode(v)); | 46 Expect.equals(identityHashCode(v), identityHashCode(v)); |
47 } | 47 } |
48 } | 48 } |
OLD | NEW |