| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The base class for all Dart objects. | 8 * The base class for all Dart objects. |
| 9 * | 9 * |
| 10 * Because Object is the root of the Dart class hierarchy, | 10 * Because Object is the root of the Dart class hierarchy, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * [Object] instances have no meaningful state, and are only useful | 25 * [Object] instances have no meaningful state, and are only useful |
| 26 * through their identity. An [Object] instance is equal to itself | 26 * through their identity. An [Object] instance is equal to itself |
| 27 * only. | 27 * only. |
| 28 */ | 28 */ |
| 29 const Object(); | 29 const Object(); |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * The equality operator. | 32 * The equality operator. |
| 33 * | 33 * |
| 34 * The default behavior for all [Object]s is to return true if and | 34 * The default behavior for all [Object]s is to return true if and |
| 35 * only if [:this:] and [other] are the same object. | 35 * only if `this` and [other] are the same object. |
| 36 * | 36 * |
| 37 * Override this method to specify a different equality relation on | 37 * Override this method to specify a different equality relation on |
| 38 * a class. The overriding method must still be an equivalence relation. | 38 * a class. The overriding method must still be an equivalence relation. |
| 39 * That is, it must be: | 39 * That is, it must be: |
| 40 * | 40 * |
| 41 * * Total: It must return a boolean for all arguments. It should never throw | 41 * * Total: It must return a boolean for all arguments. It should never throw |
| 42 * or return `null`. | 42 * or return `null`. |
| 43 * | 43 * |
| 44 * * Reflexive: For all objects `o`, `o == o` must be true. | 44 * * Reflexive: For all objects `o`, `o == o` must be true. |
| 45 * | 45 * |
| 46 * * Symmetric: For all objects `o1` and `o2`, `o1 == o2` and `o2 == o1` must | 46 * * Symmetric: For all objects `o1` and `o2`, `o1 == o2` and `o2 == o1` must |
| 47 * either both be true, or both be false. | 47 * either both be true, or both be false. |
| 48 * | 48 * |
| 49 * * Transitive: For all objects `o1`, `o2`, and `o3`, if `o1 == o2` and | 49 * * Transitive: For all objects `o1`, `o2`, and `o3`, if `o1 == o2` and |
| 50 * `o2 == o3` are true, then `o1 == o3` must be true. | 50 * `o2 == o3` are true, then `o1 == o3` must be true. |
| 51 * | 51 * |
| 52 * The method should also be consistent over time, so equality of two objects | 52 * The method should also be consistent over time, |
| 53 * should not change over time, or at least only change if one of the objects | 53 * so whether two objects are equal should only change |
| 54 * was modified. | 54 * if at least one of the objects was modified. |
| 55 * | 55 * |
| 56 * If a subclass overrides the equality operator it should override | 56 * If a subclass overrides the equality operator it should override |
| 57 * the [hashCode] method as well to maintain consistency. | 57 * the [hashCode] method as well to maintain consistency. |
| 58 */ | 58 */ |
| 59 external bool operator==(other); | 59 external bool operator==(other); |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Get a hash code for this object. | 62 * The hash code for this object. |
| 63 * | 63 * |
| 64 * All objects have hash codes. Hash codes are guaranteed to be the | 64 * A hash code is a single integer which represents the state of the object |
| 65 * same for objects that are equal when compared using the equality | 65 * that affects [==] comparisons. |
| 66 * operator [:==:]. Other than that there are no guarantees about | 66 * |
| 67 * the hash codes. They will not be consistent between runs and | 67 * All objects have hash codes. |
| 68 * there are no distribution guarantees. | 68 * The default hash code represents only the identity of the object, |
| 69 * | 69 * the same way as the default [==] implementation only considers objects |
| 70 * If a subclass overrides [hashCode] it should override the | 70 * equal if they are identical (see [identityHashCode]). |
| 71 * equality operator as well to maintain consistency. | 71 * |
| 72 * If [==] is overridden to use the object state instead, |
| 73 * the hash code must also be changed to represent that state. |
| 74 * |
| 75 * Hash codes must be the same for objects that are equal to each other |
| 76 * according to [==]. |
| 77 * The hash code of an object should only change if the object changes |
| 78 * in a way that affects equality. |
| 79 * There are no further requirements for the hash codes. |
| 80 * They need not be consistent between executions of the same program |
| 81 * and there are no distribution guarantees. |
| 82 * |
| 83 * Objects that are not equal are allowed to have the same hash code, |
| 84 * it is even technically allowed that all instances have the same hash code, |
| 85 * but if clashes happen too often, it may reduce the efficiency of hash-based |
| 86 * data structures like [HashSet] or [HashMap]. |
| 87 * |
| 88 * If a subclass overrides [hashCode], it should override the |
| 89 * [==] operator as well to maintain consistency. |
| 72 */ | 90 */ |
| 73 external int get hashCode; | 91 external int get hashCode; |
| 74 | 92 |
| 75 /** | 93 /** |
| 76 * Returns a string representation of this object. | 94 * Returns a string representation of this object. |
| 77 */ | 95 */ |
| 78 external String toString(); | 96 external String toString(); |
| 79 | 97 |
| 80 /** | 98 /** |
| 81 * Invoked when a non-existent method or property is accessed. | 99 * Invoked when a non-existent method or property is accessed. |
| 82 * | 100 * |
| 83 * Classes can override [noSuchMethod] to provide custom behavior. | 101 * Classes can override [noSuchMethod] to provide custom behavior. |
| 84 * | 102 * |
| 85 * If a value is returned, it becomes the result of the original invocation. | 103 * If a value is returned, it becomes the result of the original invocation. |
| 86 * | 104 * |
| 87 * The default behavior is to throw a [NoSuchMethodError]. | 105 * The default behavior is to throw a [NoSuchMethodError]. |
| 88 */ | 106 */ |
| 89 external dynamic noSuchMethod(Invocation invocation); | 107 external dynamic noSuchMethod(Invocation invocation); |
| 90 | 108 |
| 91 /** | 109 /** |
| 92 * A representation of the runtime type of the object. | 110 * A representation of the runtime type of the object. |
| 93 */ | 111 */ |
| 94 external Type get runtimeType; | 112 external Type get runtimeType; |
| 95 } | 113 } |
| OLD | NEW |