{"action":"created","issue":{"url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/4","repository_url":"https://api.github.com/repos/escos/Zoo_and_Animals","labels_url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/4/comments","events_url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/4/events","html_url":"https://github.com/escos/Zoo_and_Animals/issues/4","id":185659974,"number":4,"title":"Сравнение строк","user":{"login":"anastasiya-solodkaya","id":2135155,"avatar_url":"https://avatars.githubusercontent.com/u/2135155?v=3","gravatar_id":"","url":"https://api.github.com/users/anastasiya-solodkaya","html_url":"https://github.com/anastasiya-solodkaya","followers_url":"https://api.github.com/users/anastasiya-solodkaya/followers","following_url":"https://api.github.com/users/anastasiya-solodkaya/following{/other_user}","gists_url":"https://api.github.com/users/anastasiya-solodkaya/gists{/gist_id}","starred_url":"https://api.github.com/users/anastasiya-solodkaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anastasiya-solodkaya/subscriptions","organizations_url":"https://api.github.com/users/anastasiya-solodkaya/orgs","repos_url":"https://api.github.com/users/anastasiya-solodkaya/repos","events_url":"https://api.github.com/users/anastasiya-solodkaya/events{/privacy}","received_events_url":"https://api.github.com/users/anastasiya-solodkaya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-27T12:53:15Z","updated_at":"2016-11-11T07:14:32Z","closed_at":null,"body":"Сравнение строк типа\n`name == \"Петя\"` в общем случае сработает неправильно. Это сравнение по ссылке, потому что строка - это объект. Если вы хотите сравнивать два объекта, то вам нужен метод **equals** или какой-то другой, который подходит и есть в соответствующем классе.\n\nВаш код работает потому, что у вас простой случай и java создает только один экземпляр со значением \"травоядное\", например, и использует его везде. Это особенность именно java, и ей не стоит пользоваться. Она есть на слайжах со строками, кстати. Там чуть подробнее. Если бы не было этой особенности, то \n\n``` java\nString s1 = \"травоядное\";\nString s2 = \"травоядное\";\nSystem.out.println(s1 == s2);\n```\n\nвернул бы **false**. Но у нас тут **true**.\n\nВот тут может быть станет чуть понятнее, как оно работает. В любом случае, вам стоит всегда использовать equals вместо == для объектов (кроме enums)\n\n``` java\nString s1 = \"abc\";\nString s2 = \"abc\";\nString s3 = \"a\" + \"bc\";\nString s4 = \"a\";\nString s5 = s4 + \"bc\";\nString s6 = new String(\"abc\");\nString s7 = s2 + \"\";\n\nSystem.out.printf(\"(s1 vs s2) %1$s == %2$s ? %3$s\\t%1$s equals %2$s ? %4$s %n\", s1, s2, s1 == s2, s1.equals(s2));\nSystem.out.printf(\"(s1 vs s3) %1$s == %2$s ? %3$s\\t%1$s equals %2$s ? %4$s %n\", s1, s3, s1 == s3, s1.equals(s3));\nSystem.out.printf(\"(s1 vs s5) %1$s == %2$s ? %3$s\\t%1$s equals %2$s ? %4$s %n\", s1, s5, s1 == s5, s1.equals(s5));\nSystem.out.printf(\"(s1 vs s6) %1$s == %2$s ? %3$s\\t%1$s equals %2$s ? %4$s %n\", s1, s6, s1 == s6, s1.equals(s6));\nSystem.out.printf(\"(s1 vs s7) %1$s == %2$s ? %3$s\\t%1$s equals %2$s ? %4$s %n\", s1, s7, s1 == s7, s1.equals(s7));\n```\n"},"comment":{"url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/comments/259896195","html_url":"https://github.com/escos/Zoo_and_Animals/issues/4#issuecomment-259896195","issue_url":"https://api.github.com/repos/escos/Zoo_and_Animals/issues/4","id":259896195,"user":{"login":"anastasiya-solodkaya","id":2135155,"avatar_url":"https://avatars.githubusercontent.com/u/2135155?v=3","gravatar_id":"","url":"https://api.github.com/users/anastasiya-solodkaya","html_url":"https://github.com/anastasiya-solodkaya","followers_url":"https://api.github.com/users/anastasiya-solodkaya/followers","following_url":"https://api.github.com/users/anastasiya-solodkaya/following{/other_user}","gists_url":"https://api.github.com/users/anastasiya-solodkaya/gists{/gist_id}","starred_url":"https://api.github.com/users/anastasiya-solodkaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anastasiya-solodkaya/subscriptions","organizations_url":"https://api.github.com/users/anastasiya-solodkaya/orgs","repos_url":"https://api.github.com/users/anastasiya-solodkaya/repos","events_url":"https://api.github.com/users/anastasiya-solodkaya/events{/privacy}","received_events_url":"https://api.github.com/users/anastasiya-solodkaya/received_events","type":"User","site_admin":false},"created_at":"2016-11-11T07:14:32Z","updated_at":"2016-11-11T07:14:32Z","body":"Таки я не права, оказывается, вы в поле все еще строку испольуете, так что там нужен equals. Это я закрываю, посмотрите комментарий про enums. :)"}}
{"actor":{"display_login":"anastasiya-solodkaya"}}