{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/28844","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/28844/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/28844/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/28844/events","html_url":"https://github.com/dart-lang/sdk/issues/28844","id":209105890,"number":28844,"title":"please, clarify description of Object.hashCode","user":{"login":"alsemenov","id":4629015,"avatar_url":"https://avatars.githubusercontent.com/u/4629015?v=3","gravatar_id":"","url":"https://api.github.com/users/alsemenov","html_url":"https://github.com/alsemenov","followers_url":"https://api.github.com/users/alsemenov/followers","following_url":"https://api.github.com/users/alsemenov/following{/other_user}","gists_url":"https://api.github.com/users/alsemenov/gists{/gist_id}","starred_url":"https://api.github.com/users/alsemenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alsemenov/subscriptions","organizations_url":"https://api.github.com/users/alsemenov/orgs","repos_url":"https://api.github.com/users/alsemenov/repos","events_url":"https://api.github.com/users/alsemenov/events{/privacy}","received_events_url":"https://api.github.com/users/alsemenov/received_events","type":"User","site_admin":false},"labels":[{"id":219928215,"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-documentation","name":"area-documentation","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":{"login":"lrhn","id":4865287,"avatar_url":"https://avatars.githubusercontent.com/u/4865287?v=3","gravatar_id":"","url":"https://api.github.com/users/lrhn","html_url":"https://github.com/lrhn","followers_url":"https://api.github.com/users/lrhn/followers","following_url":"https://api.github.com/users/lrhn/following{/other_user}","gists_url":"https://api.github.com/users/lrhn/gists{/gist_id}","starred_url":"https://api.github.com/users/lrhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lrhn/subscriptions","organizations_url":"https://api.github.com/users/lrhn/orgs","repos_url":"https://api.github.com/users/lrhn/repos","events_url":"https://api.github.com/users/lrhn/events{/privacy}","received_events_url":"https://api.github.com/users/lrhn/received_events","type":"User","site_admin":false},"assignees":[{"login":"lrhn","id":4865287,"avatar_url":"https://avatars.githubusercontent.com/u/4865287?v=3","gravatar_id":"","url":"https://api.github.com/users/lrhn","html_url":"https://github.com/lrhn","followers_url":"https://api.github.com/users/lrhn/followers","following_url":"https://api.github.com/users/lrhn/following{/other_user}","gists_url":"https://api.github.com/users/lrhn/gists{/gist_id}","starred_url":"https://api.github.com/users/lrhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lrhn/subscriptions","organizations_url":"https://api.github.com/users/lrhn/orgs","repos_url":"https://api.github.com/users/lrhn/repos","events_url":"https://api.github.com/users/lrhn/events{/privacy}","received_events_url":"https://api.github.com/users/lrhn/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2017-02-21T10:43:33Z","updated_at":"2017-02-28T10:39:42Z","closed_at":null,"body":"The [description](https://api.dartlang.org/stable/1.21.1/dart-core/Object/hashCode.html) for property Object.hashCode reads:\r\n\r\n> int hashCode\r\n> Get a hash code for this object.\r\n> \r\n> All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. **They will not be consistent between runs** and there are no distribution guarantees.\r\n> \r\n> If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.\r\n\r\nIt is not clear whether the same value will be returned for subsequent calls inside same virtual machine?\r\nI.e. \r\n```dart\r\nmain() {\r\n  Object o = new Object();\r\n  int h1 = o.hashCode;\r\n  int h2 = o.hashCode;\r\n// is it always h1==h2, regardless of time and place they were obtained from the same instance?\r\n}\r\n```\r\n\r\nThe question actually splits in two:\r\n1. How the `Object.hashCode` implementation works?\r\n2. How descendants, overriding the `hashCode` should be implemented? (i.e. if it is allowed to return different values for different reads?)\r\n\r\nI do understand, that `hashCode` value must be constant during virtual machine execution time, but I'd like this to be clearly documented.\r\n"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/283004924","html_url":"https://github.com/dart-lang/sdk/issues/28844#issuecomment-283004924","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/28844","id":283004924,"user":{"login":"alsemenov","id":4629015,"avatar_url":"https://avatars.githubusercontent.com/u/4629015?v=3","gravatar_id":"","url":"https://api.github.com/users/alsemenov","html_url":"https://github.com/alsemenov","followers_url":"https://api.github.com/users/alsemenov/followers","following_url":"https://api.github.com/users/alsemenov/following{/other_user}","gists_url":"https://api.github.com/users/alsemenov/gists{/gist_id}","starred_url":"https://api.github.com/users/alsemenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alsemenov/subscriptions","organizations_url":"https://api.github.com/users/alsemenov/orgs","repos_url":"https://api.github.com/users/alsemenov/repos","events_url":"https://api.github.com/users/alsemenov/events{/privacy}","received_events_url":"https://api.github.com/users/alsemenov/received_events","type":"User","site_admin":false},"created_at":"2017-02-28T10:39:42Z","updated_at":"2017-02-28T10:39:42Z","body":"Do I understand correctly, that `hashCode` is not allowed to be null? Otherwise, `HashMap` will be broken. Since `int` is not a primitive type, it is not quite obvious. Could you document this?"}}
{"actor":{"display_login":"alsemenov"}}