{"id":295267,"date":"2019-11-27T09:00:19","date_gmt":"2019-11-27T09:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295267"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295267","title":{"rendered":"\u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 instanceof \u0432 Java 14"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477654\/\">\u041d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438 \u043d\u043e\u0432\u0430\u044f, <a href=\"http:\/\/openjdk.java.net\/projects\/jdk\/14\/\">14-\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/a> Java, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043d\u043e\u0432\u044b\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044f Java. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/openjdk.java.net\/jeps\/305\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d-\u043c\u0430\u0442\u0447\u0438\u043d\u0433 \u043f\u043e \u0442\u0438\u043f\u0443<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0433\u043e (\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e) \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>instanceof<\/code>.<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043d\u043e\u0432\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e. \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d-\u043c\u0430\u0442\u0447\u0438\u043d\u0433 \u043f\u043e \u0442\u0438\u043f\u0443 \u0435\u0449\u0451 \u043d\u0435 \u0432\u043e\u0448\u0451\u043b \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 JDK, \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 <a href=\"https:\/\/openjdk.java.net\/projects\/amber\/\">\u043f\u0440\u043e\u0435\u043a\u0442\u0430 Amber<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u043e\u0432\u044b\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 Java, \u0438 <a href=\"https:\/\/builds.shipilev.net\/workspaces\/\">\u0441\u043e\u0431\u0440\u0430\u0442\u044c JDK<\/a> \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0435\u0440\u0441\u0438\u044e Java, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c JDK 14:<\/p>\n<pre><code class=\"bash\">&gt; java -version openjdk version \"14-internal\" 2020-03-17 OpenJDK Runtime Environment (build 14-internal+0-adhoc.osboxes.amber-amber) OpenJDK 64-Bit Server VM (build 14-internal+0-adhoc.osboxes.amber-amber, mixed mode, sharing)<\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u0432\u0435\u0440\u043d\u043e.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u0441\u043e \u00ab\u0441\u0442\u0430\u0440\u044b\u043c\u00bb \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>instanceof<\/code> \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"java\">public class A {     public static void main(String[] args) {         new A().f(\"Hello, world!\");     }      public void f(Object obj) {         if (obj instanceof String) {             String str = (String) obj;             System.out.println(str.toLowerCase());         }     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">&gt; java A.java hello, world!<\/code><\/pre>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u042d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0442\u0438\u043f \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0438\u0437\u043e \u0434\u043d\u044f \u0432 \u0434\u0435\u043d\u044c, \u043a\u0430\u043a\u0443\u044e \u0431\u044b \u0432\u0435\u0440\u0441\u0438\u044e Java \u043c\u044b \u0431\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438, \u0445\u043e\u0442\u044c 1.0, \u0445\u043e\u0442\u044c 13.<br \/>  \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0432 \u0440\u0443\u043a\u0430\u0445 Java 14, \u0438 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>instanceof<\/code> (\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0443 \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c):<\/p>\n<pre><code class=\"java\">if (obj instanceof String str) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">&gt; java --enable-preview --source 14 A.java hello, world!<\/code><\/pre>\n<p>  \u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e. \u041a\u043e\u0434 \u0441\u0442\u0430\u043b \u0447\u0438\u0449\u0435, \u043a\u043e\u0440\u043e\u0447\u0435, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0435\u0435 \u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0435\u0435. \u0411\u044b\u043b\u043e \u0442\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430 String, \u0441\u0442\u0430\u043b\u043e \u043e\u0434\u043d\u043e. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code>--enable-preview --source 14<\/code>, \u0442.\u043a. \u043d\u043e\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/openjdk.java.net\/jeps\/12\">preview feature<\/a>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b A.java \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0431\u0435\u0437 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0422\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/openjdk.java.net\/jeps\/330\">\u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c<\/a> \u0432 Java 11.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0432\u043e\u0440\u043e\u0447\u0435\u043d\u043d\u043e\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e:<\/p>\n<pre><code class=\"java\">if (obj instanceof String str &amp;&amp; str.length() &gt; 5) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438?<\/p>\n<pre><code class=\"java\">if (str.length() &gt; 5 &amp;&amp; obj instanceof String str) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">A.java:7: error: cannot find symbol         if (str.length() &gt; 5 &amp;&amp; obj instanceof String str) {             ^<\/code><\/pre>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0427\u0435\u0433\u043e \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c: \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>str<\/code> \u0435\u0449\u0451 \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430.<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0447\u0442\u043e \u0441 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e? \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f final \u0438\u043b\u0438 \u043d\u0435\u0442? \u041f\u0440\u043e\u0431\u0443\u0435\u043c:<\/p>\n<pre><code class=\"java\">if (obj instanceof String str) {     str = \"World, hello!\";     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">A.java:8: error: pattern binding str may not be assigned     str = \"World, hello!\";     ^<\/code><\/pre>\n<p>  \u0410\u0433\u0430, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f final. \u042d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u0435\u043d\u044c\u043a\u043e\u0435. \u041f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 Java \u0447\u0442\u043e-\u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f final. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0451 \u0432 Java \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044f\u0432\u043b\u044f\u043b\u043e\u0441\u044c non-final: \u043f\u043e\u043b\u044f, \u043a\u043b\u0430\u0441\u0441\u044b, \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0434\u0430\u0436\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043b\u044f\u043c\u0431\u0434. \u0410 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e final. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u00ab\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f\u00bb \u0437\u0434\u0435\u0441\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u0414\u0430 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0440\u043c\u0438\u043d \u00abpattern binding\u00bb. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0442\u043d\u044b\u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0435 \u00ab\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f\u00bb, \u0430 \u00ab\u0431\u0438\u043d\u0434\u0438\u043d\u0433 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u00bb (\u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0441\u043b\u043e\u0432\u043e \u00abbinding\u00bb \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439).<\/p>\n<p>  \u0421 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c. \u041f\u043e\u0435\u0445\u0430\u043b\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435. \u0412\u0434\u0440\u0443\u0433 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u00ab\u0441\u043b\u043e\u043c\u0430\u0442\u044c\u00bb \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440?<\/p>\n<p>  \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438 \u0431\u0438\u043d\u0434\u0438\u043d\u0433 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c?<\/p>\n<pre><code class=\"java\">if (obj instanceof String obj) {     System.out.println(obj.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">A.java:7: error: variable obj is already defined in method f(Object) if (obj instanceof String obj) {                           ^<\/code><\/pre>\n<p>  \u041b\u043e\u0433\u0438\u0447\u043d\u043e. \u041f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u042d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0432\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>obj<\/code> \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437 \u0432 \u0442\u043e\u0439 \u0436\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">if (obj instanceof String str &amp;&amp; obj instanceof String str) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">A.java:7: error: illegal attempt to redefine an existing match binding if (obj instanceof String str &amp;&amp; obj instanceof String str) {                               ^<\/code><\/pre>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u0434\u0451\u0436\u0435\u043d \u043a\u0430\u043a \u0431\u0435\u0442\u043e\u043d.<\/p>\n<p>  \u0427\u0442\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0438\u0433\u0440\u0430\u0435\u043c\u0441\u044f \u0441 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u043c\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 \u0432 \u0432\u0435\u0442\u043a\u0435 <code>if<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0431\u0438\u043d\u0434\u0438\u043d\u0433, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0432 \u0432\u0435\u0442\u043a\u0435 <code>else<\/code>, \u0435\u0441\u043b\u0438 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435?<\/p>\n<pre><code class=\"java\">if (!(obj instanceof String str)) {     System.out.println(\"not a string\"); } else {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  \u0421\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0434\u0451\u0436\u0435\u043d, \u043d\u043e \u0435\u0449\u0451 \u0438 \u0443\u043c\u0451\u043d.<\/p>\n<p>  \u0410 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a?<\/p>\n<pre><code class=\"java\">if (obj instanceof String str &amp;&amp; true) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 <code>obj instanceof String str<\/code>.<\/p>\n<p>  \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u00ab\u0441\u043b\u043e\u043c\u0430\u0442\u044c\u00bb \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440?<\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442, \u0442\u0430\u043a?<\/p>\n<pre><code class=\"java\">if (obj instanceof String str || false) {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">A.java:8: error: cannot find symbol     System.out.println(str.toLowerCase());                        ^ <\/code><\/pre>\n<p>  \u0410\u0433\u0430! \u0412\u043e\u0442 \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0431\u0430\u0433. \u0412\u0435\u0434\u044c \u0432\u0441\u0435 \u0442\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b:<\/p>\n<ul>\n<li><code>obj instanceof String str<\/code><\/li>\n<li><code>obj instanceof String str &amp;&amp; true<\/code><\/li>\n<li><code>obj instanceof String str || false<\/code><\/li>\n<\/ul>\n<p>  \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0430\u0432\u0438\u043b\u0430 flow scoping \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e <a href=\"http:\/\/cr.openjdk.java.net\/~briangoetz\/amber\/pattern-semantics.html#scoping-of-pattern-variables\">\u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b<\/a>, \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u043e \u0435\u0441\u043b\u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0438\u0441\u0442\u043e \u0441 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f, \u0442\u043e \u044f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0430\u0433.<\/p>\n<p>  \u041d\u043e \u0434\u0430 \u043b\u0430\u0434\u043d\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0449\u0451 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c. \u0411\u0443\u0434\u0435\u0442 \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"java\">if (!(obj instanceof String str)) {     throw new RuntimeException(); } System.out.println(str.toLowerCase());<\/code><\/pre>\n<p>  \u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443:  <\/p>\n<pre><code class=\"java\">if (!(obj instanceof String str)) {     throw new RuntimeException(); } else {     System.out.println(str.toLowerCase()); }<\/code><\/pre>\n<p>  \u0410 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b, \u0442\u043e \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<p>  \u0427\u0442\u043e \u043d\u0430\u0441\u0447\u0451\u0442 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u044f \u043f\u043e\u043b\u0435\u0439?<\/p>\n<pre><code class=\"java\">public class A {     private String str;      public void f(Object obj) {         if (obj instanceof String str) {             System.out.println(str.toLowerCase());         } else {             System.out.println(str.toLowerCase());         }     } }<\/code><\/pre>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u0430\u0440\u0443\u0433\u0430\u043b\u0441\u044f. \u042d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0433\u043b\u0438 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f. \u0414\u043b\u044f \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u0432 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432, \u0432\u0438\u0434\u0438\u043c\u043e, \u0442\u043e\u0436\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u0440\u0443\u043f\u043e\u043a. \u041e\u0434\u043d\u043e \u043d\u0435\u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043a\u0430\u043a \u0432\u0430\u0448\u0430 \u0432\u0435\u0442\u043a\u0430 <code>if<\/code> \u0441\u043b\u043e\u043c\u0430\u043b\u0430\u0441\u044c:<\/p>\n<pre><code class=\"java\">private boolean isOK() {     return false; }  public void f(Object obj) {     if (obj instanceof String str || isOK()) {         System.out.println(str.toLowerCase());     } else {         System.out.println(str.toLowerCase());     } }<\/code><\/pre>\n<p>  \u0412 \u043e\u0431\u0435\u0438\u0445 \u0432\u0435\u0442\u0432\u044f\u0445 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435 <code>str<\/code>, \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043d\u0435\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442. \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0441\u043f\u0435\u043a\u0446\u0438\u0438 \u0432 IDE \u0438 \u0440\u0430\u0437\u043d\u0443\u044e \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0410 \u0435\u0449\u0451 \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0432\u0430\u043b\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 <code>this<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439. \u042d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0427\u0442\u043e \u0435\u0449\u0451 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e? \u041a\u0430\u043a \u0438 \u00ab\u0441\u0442\u0430\u0440\u044b\u0439\u00bb <code>instanceof<\/code>, \u043d\u043e\u0432\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043c\u0430\u0442\u0447\u0438\u0442 <code>null<\/code>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <code>null<\/code>:<\/p>\n<pre><code class=\"java\">if (obj instanceof String str) {     System.out.println(str.toLowerCase()); \/\/ \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442 NullPointerException }<\/code><\/pre>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438:<\/p>\n<pre><code class=\"java\">if (a != null) {     B b = a.getB();     if (b != null) {         C c = b.getC();         if (c != null) {             System.out.println(c.getSize());         }     } }<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>instanceof<\/code>, \u0442\u043e \u043a\u043e\u0434 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">if (a != null &amp;&amp; a.getB() instanceof B b &amp;&amp; b.getC() instanceof C c) {     System.out.println(c.getSize()); }<\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0447\u0442\u043e \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f. \u0421\u0442\u0430\u043b\u0438 \u043b\u0438 \u0431\u044b \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0438\u0434\u0438\u043e\u043c\u0443?<\/p>\n<p>  \u0427\u0442\u043e \u043d\u0430\u0441\u0447\u0451\u0442 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432?<\/p>\n<pre><code class=\"java\">import java.util.List;  public class A {     public static void main(String[] args) {         new A().f(List.of(1, 2, 3));     }      public void f(Object obj) {         if (obj instanceof List&lt;Integer&gt; list) {             System.out.println(list.size());         }     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">&gt; java --enable-preview --source 14 A.java Note: A.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3<\/code><\/pre>\n<p>  \u041e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0415\u0441\u043b\u0438 \u00ab\u0441\u0442\u0430\u0440\u044b\u0439\u00bb <code>instanceof<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>instanceof List<\/code> \u0438\u043b\u0438 <code>instanceof List&lt;?&gt;<\/code>, \u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c. \u0416\u0434\u0451\u043c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043f\u0430\u0434\u0451\u0442\u0441\u044f \u0432\u043e\u0442 \u0432 \u0442\u0430\u043a\u0443\u044e \u043b\u043e\u0432\u0443\u0448\u043a\u0443:<\/p>\n<pre><code class=\"java\">if (obj instanceof List&lt;Integer&gt; list) {     System.out.println(\"Int list of size \" + list.size()); } else if (obj instanceof List&lt;String&gt; list) {     System.out.println(\"String list of size \" + list.size()); }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/b><\/p>\n<div class=\"spoiler_text\">\u041e\u0442\u0432\u0435\u0442: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 reified generics \u0432 Java.<\/div>\n<\/div>\n<p>  \u0418\u041c\u0425\u041e, \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044f \u043d\u0435 \u0437\u043d\u0430\u044e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0435\u0451 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041f\u043e\u0445\u043e\u0436\u0435, \u043e\u043f\u044f\u0442\u044c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0438\u043d\u0441\u043f\u0435\u043a\u0446\u0438\u0438 \u0432 IDE.<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c, \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d-\u043c\u0430\u0442\u0447\u0438\u043d\u0433 \u043f\u043e \u0442\u0438\u043f\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u043e. \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>instanceof<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442 \u043d\u0430 \u0442\u0438\u043f, \u043d\u043e \u0435\u0449\u0451 \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0431\u0438\u043d\u0434\u0438\u043d\u0433 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u0448\u0443\u043c\u0430, \u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0440\u0430\u0437\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <code>equals()<\/code> \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"java\">public class Point {     private final int x, y;     \u2026      @Override     public int hashCode() {         return Objects.hash(x, y);     }      @Override     public boolean equals(Object obj) {         return obj instanceof Point p &amp;&amp; p.x == this.x &amp;&amp; p.y == this.y;     } }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0449\u0451 \u043a\u043e\u0440\u043e\u0447\u0435. \u041a\u0430\u043a?<\/b><\/p>\n<div class=\"spoiler_text\">\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/openjdk.java.net\/jeps\/359\">\u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0439\u0434\u0443\u0442 \u0432 Java 14. \u041e \u043d\u0438\u0445 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437.<\/div>\n<\/div>\n<p>  \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0440\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\u041d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 (\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 <code>instanceof || false<\/code>).<\/li>\n<li>\u041f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u043e\u043b\u0435\u0439.<\/li>\n<li><code>instanceof<\/code> \u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438.<\/li>\n<\/ul>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u043c\u0435\u043b\u043a\u0438\u0435 \u043f\u0440\u0438\u0434\u0438\u0440\u043a\u0438, \u043d\u0435\u0436\u0435\u043b\u0438 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0438. \u0412 \u0446\u0435\u043b\u043e\u043c, \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>instanceof<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u0441\u0442\u043e\u044f\u0442 \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044f\u0437\u044b\u043a. \u0410 \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0449\u0451 \u0432\u044b\u0439\u0434\u0435\u0442 \u0438\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f preview \u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0435\u0439 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0443\u0439\u0442\u0438 \u0441 Java 8 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e Java.<\/p>\n<p>  P.S. \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c <a href=\"https:\/\/t.me\/miniJUG\">\u043a\u0430\u043d\u0430\u043b \u0432 Telegram<\/a>, \u0433\u0434\u0435 \u044f \u043f\u0438\u0448\u0443 \u043e \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u0445 Java. \u041f\u0440\u0438\u0437\u044b\u0432\u0430\u044e \u0432\u0430\u0441 \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f.<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/477654\/\"> https:\/\/habr.com\/ru\/post\/477654\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/477654\/\">\u041d\u0435 \u0437\u0430 \u0433\u043e\u0440\u0430\u043c\u0438 \u043d\u043e\u0432\u0430\u044f, <a href=\"http:\/\/openjdk.java.net\/projects\/jdk\/14\/\">14-\u044f \u0432\u0435\u0440\u0441\u0438\u044f<\/a> Java, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043d\u043e\u0432\u044b\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044f Java. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/openjdk.java.net\/jeps\/305\">\u043f\u0430\u0442\u0442\u0435\u0440\u043d-\u043c\u0430\u0442\u0447\u0438\u043d\u0433 \u043f\u043e \u0442\u0438\u043f\u0443<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0433\u043e (\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e) \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>instanceof<\/code>.<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u043d\u043e\u0432\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e. \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0442\u0442\u0435\u0440\u043d-\u043c\u0430\u0442\u0447\u0438\u043d\u0433 \u043f\u043e \u0442\u0438\u043f\u0443 \u0435\u0449\u0451 \u043d\u0435 \u0432\u043e\u0448\u0451\u043b \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 JDK, \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 <a href=\"https:\/\/openjdk.java.net\/projects\/amber\/\">\u043f\u0440\u043e\u0435\u043a\u0442\u0430 Amber<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0435\u0434\u0451\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u043e\u0432\u044b\u0445 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 Java, \u0438 <a href=\"https:\/\/builds.shipilev.net\/workspaces\/\">\u0441\u043e\u0431\u0440\u0430\u0442\u044c JDK<\/a> \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-295267","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295267"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295267\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}