{"id":292340,"date":"2019-07-20T15:00:12","date_gmt":"2019-07-20T15:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=292340"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=292340","title":{"rendered":"\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0432 Java"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (pattern matching) \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u044f\u0437\u044b\u043a\u0430. Java \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 pattern matching, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u0434\u044b \u0447\u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043f\u0435\u0440\u0435\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0435\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c. <\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Java 8, \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 pattern matching \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u043a \u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p><i><b>Constant pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u0441 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438. \u0412 Java switch \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u0430, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0440\u043e\u043a\u0438. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 equals().<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (data) {       case new Person(\"man\")    -&gt; System.out.println(\"man\");       case new Person(\"woman\")  -&gt; System.out.println(\"woman\");       case new Person(\"child\")  -&gt; System.out.println(\"child\");               case null                 -&gt; System.out.println(\"Null value \");       default                   -&gt; System.out.println(\"Default value: \" + data); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.ConstantPattern.matches;  matches(data,       new Person(\"man\"),    () -&gt;  System.out.println(\"man\");       new Person(\"woman\"),  () -&gt;  System.out.println(\"woman\");       new Person(\"child\"),  () -&gt;  System.out.println(\"child\");               Null.class,           () -&gt;  System.out.println(\"Null value \"),       Else.class,           () -&gt;  System.out.println(\"Default value: \" + data) );<\/code><\/pre>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><i><b>Tuple pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d \u0441 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (side, width) {       case \"top\",    25 -&gt; System.out.println(\"top\");       case \"bottom\", 30 -&gt; System.out.println(\"bottom\");       case \"left\",   15 -&gt; System.out.println(\"left\");               case \"right\",  15 -&gt; System.out.println(\"right\");        case null         -&gt; System.out.println(\"Null value \");       default           -&gt; System.out.println(\"Default value \"); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c 4 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 6 \u0432\u0435\u0442\u043e\u043a.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.TuplePattern.matches;  matches(side, width,       \"top\",    25,  () -&gt; System.out.println(\"top\");       \"bottom\", 30,  () -&gt; System.out.println(\"bottom\");       \"left\",   15,  () -&gt; System.out.println(\"left\");               \"right\",  15,  () -&gt; System.out.println(\"right\");                Null.class,    () -&gt; System.out.println(\"Null value\"),       Else.class,    () -&gt; System.out.println(\"Default value\") );<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Type test pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0412 Java \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f, \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u0438\u043f\u0443 \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (data) {       case Integer i  -&gt; System.out.println(i * i);       case Byte    b  -&gt; System.out.println(b * b);       case Long    l  -&gt; System.out.println(l * l);               case String  s  -&gt; System.out.println(s * s);       case null       -&gt; System.out.println(\"Null value \");       default         -&gt; System.out.println(\"Default value: \" + data); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.VerifyPattern.matches;  matches(data,       Integer.class, i  -&gt; { System.out.println(i * i); },       Byte.class,    b  -&gt; { System.out.println(b * b); },       Long.class,    l  -&gt; { System.out.println(l * l); },       String.class,  s  -&gt; { System.out.println(s * s); },       Null.class,    () -&gt; { System.out.println(\"Null value \"); },       Else.class,    () -&gt; { System.out.println(\"Default value: \" + data); } );<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Guard pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (data) {       case Integer i &amp;&amp; i != 0     -&gt; System.out.println(i * i);       case Byte    b &amp;&amp; b &gt; -1     -&gt; System.out.println(b * b);       case Long    l &amp;&amp; l &lt; 5      -&gt; System.out.println(l * l);       case String  s &amp;&amp; !s.empty() -&gt; System.out.println(s * s);       case null                    -&gt; System.out.println(\"Null value \");       default                      -&gt; System.out.println(\"Default: \" + data); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c\u0438. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.GuardPattern.matches;  matches(data,                  Integer.class, i  -&gt; i != 0,  i  -&gt; { System.out.println(i * i); },       Byte.class,    b  -&gt; b &gt; -1,  b  -&gt; { System.out.println(b * b); },       Long.class,    l  -&gt; l == 5,  l  -&gt; { System.out.println(l * l); },       Null.class,    () -&gt; { System.out.println(\"Null value \"); },       Else.class,    () -&gt; { System.out.println(\"Default value: \" + data); } );<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f: lessThan\/lt, greaterThan\/gt, lessThanOrEqual\/le, greaterThanOrEqual\/ge,<br \/>  equal\/eq, notEqual\/ne. \u0410 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043c\u0435\u043d\u0438\u0442\u044c: always\/yes, never\/no.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">matches(data,                  Integer.class, ne(0),  i  -&gt; { System.out.println(i * i); },       Byte.class,    gt(-1), b  -&gt; { System.out.println(b * b); },       Long.class,    eq(5),  l  -&gt; { System.out.println(l * l); },       Null.class,    () -&gt; { System.out.println(\"Null value \"); },       Else.class,    () -&gt; { System.out.println(\"Default value: \" + data); } );<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Deconstruction pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435. \u0412 Java \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f, \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u0438\u043f\u0443, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u043b\u044f\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">let (int w, int h) = figure;  switch (figure) {       case Rectangle(int w, int h) -&gt; out.println(\"square: \" + (w * h));       case Circle(int r)        -&gt; out.println(\"square: \" + (2 * Math.PI * r));       default                      -&gt; out.println(\"Default square: \" + 0); };  for ((int w, int h) :  listFigures) {       System.out.println(\"square: \" + (w * h)); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 3 \u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 3 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import static org.kl.pattern.DeconstructPattern.matches; import static org.kl.pattern.DeconstructPattern.foreach; import static org.kl.pattern.DeconstructPattern.let;  Figure figure = new Rectangle();  let(figure, (int w, int h) -&gt; {       System.out.println(\"border: \" + w + \" \" + h)); });  matches(figure,       Rectangle.class, (int w, int h) -&gt; out.println(\"square: \" + (w * h)),       Circle.class,  (int r)        -&gt; out.println(\"square: \" + (2 * Math.PI * r)),       Else.class,      ()             -&gt; out.println(\"Default square: \" + 0) );  foreach(listRectangles, (int w, int h) -&gt; {       System.out.println(\"square: \" + (w * h)); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435, \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u042d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 <a href=\"https:\/\/habr.com\/ru\/users\/extract\/\" class=\"user_link\">Extract<\/a>.<br \/>  \u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u043d\u0430 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b IntRef, FloatRef \u0438 \u0442.\u0434. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.type.IntRef; ...  @Extract public void deconstruct(IntRef width, IntRef height) {       width.set(this.width);       height.set(this.height);  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Java 11, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Figure figure = new Rectangle();  let(figure, (var w, var h) -&gt; {       System.out.println(\"border: \" + w + \" \" + h)); });  matches(figure,       Rectangle.class, (var w, var h) -&gt; out.println(\"square: \" + (w * h)),       Circle.class,  (var r)        -&gt; out.println(\"square: \" + (2 * Math.PI * r)),       Else.class,      ()             -&gt; out.println(\"Default square: \" + 0) );  foreach(listRectangles, (var w, var h) -&gt; {       System.out.println(\"square: \" + (w * h)); });<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Property pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u043b\u044f\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u0438\u0445 \u0438\u043c\u0435\u043d\u0430\u043c. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0443\u0436\u043d\u044b\u043c \u0438 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">let (w: int w, h:int h) = figure;  switch (figure) {       case Rect(w: int w == 5,  h: int h == 10) -&gt; out.println(\"sqr: \" + (w * h));       case Rect(w: int w == 10, h: int h == 15) -&gt; out.println(\"sqr: \" + (w * h));       case Circle   (r: int r) -&gt; out.println(\"sqr: \" + (2 * Math.PI * r));       default                  -&gt; out.println(\"Default sqr: \" + 0); };  for ((w: int w, h: int h) :  listRectangles) {       System.out.println(\"square: \" + (w * h)); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 3 \u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 3 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import static org.kl.pattern.PropertyPattern.matches; import static org.kl.pattern.PropertyPattern.foreach; import static org.kl.pattern.PropertyPattern.let; import static org.kl.pattern.PropertyPattern.of;     Figure figure = new Rectangle();  let(figure, of(\"w\", \"h\"), (int w, int h) -&gt; {       System.out.println(\"border: \" + w + \" \" + h)); });  matches(figure,     Rect.class, of(\"w\", 5,  \"h\", 10), (int w, int h) -&gt; out.println(\"sqr: \" + (w * h)),     Rect.class, of(\"w\", 10, \"h\", 15), (int w, int h) -&gt; out.println(\"sqr: \" + (w * h)),     Circle.class,  of(\"r\"), (int r)  -&gt; out.println(\"sqr: \" + (2 * Math.PI * r)),     Else.class,    ()                -&gt; out.println(\"Default sqr: \" + 0) );  foreach(listRectangles, of(\"x\", \"y\"), (int w, int h) -&gt; {       System.out.println(\"square: \" + (w * h)); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Figure figure = new Rect();  let(figure, Rect::w, Rect::h, (int w, int h) -&gt; {       System.out.println(\"border: \" + w + \" \" + h)); });  matches(figure,     Rect.class,    Rect::w, Rect::h, (int w, int h) -&gt; out.println(\"sqr: \" + (w * h)),     Circle.class,  Circle::r, (int r)  -&gt; out.println(\"sqr: \" + (2 * Math.PI * r)),     Else.class,    ()                  -&gt; System.out.println(\"Default sqr: \" + 0) );  foreach(listRectangles, Rect::w, Rect::h, (int w, int h) -&gt; {       System.out.println(\"square: \" + (w * h)); });<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Position pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f. \u0412 Java \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f, \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u0438\u043f\u0443, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u043b\u044f\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (data) {       case Circle(5)   -&gt; System.out.println(\"small circle\");       case Circle(15)  -&gt; System.out.println(\"middle circle\");       case null        -&gt; System.out.println(\"Null value \");       default          -&gt; System.out.println(\"Default value: \" + data); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0440\u0430\u0437\u0443 4 \u043f\u043e\u043b\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.PositionPattern.matches; import static org.kl.pattern.PositionPattern.of;  matches(data,                  Circle.class,  of(5),  () -&gt; { System.out.println(\"small circle\"); },       Circle.class,  of(15), () -&gt; { System.out.println(\"middle circle\"); },       Null.class,            () -&gt; { System.out.println(\"Null value \"); },       Else.class,            () -&gt; { System.out.println(\"Default value: \" + data); } );<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f, \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 @Exclude. \u042d\u0442\u0438 \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">class Circle {       private int radius;        @Exclude       private int temp;  }<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Static pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0438 \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0430\u0431\u0440\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Optional some = ...;  switch (some) {       case Optional.empty()   -&gt; System.out.println(\"empty value\");       case Optional.of(var v) -&gt; System.out.println(\"value: \" + v);       default                 -&gt; System.out.println(\"Default value\"); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 3 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import static org.kl.pattern.StaticPattern.matches; import static org.kl.pattern.StaticPattern.of;  Optional some = ...;  matches(figure,       Optinal.class, of(\"empty\"), ()      -&gt; System.out.println(\"empty value\"),       Optinal.class, of(\"of\")   , (var v) -&gt; System.out.println(\"value: \" + v),       Else.class,                 ()      -&gt; System.out.println(\"Default value\") ); <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0435, \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 <a href=\"https:\/\/habr.com\/ru\/users\/extract\/\" class=\"user_link\">Extract<\/a>. <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Extract    public void of(IntRef value) {       value.set(this.value);  }<\/code><\/pre>\n<p>  <\/p>\n<p><i><b>Sequence pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">List&lt;Integer&gt; list = ...;  switch (list) {       case Ranges.head(var h) -&gt; System.out.println(\"list head: \" + h);       case Ranges.tail(var t) -&gt; System.out.println(\"list tail: \" + t);       case Ranges.empty()     -&gt; System.out.println(\"Empty value\");       default                 -&gt; System.out.println(\"Default value\"); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.range.Ranges; import static org.kl.pattern.SequencePattern.matches;  List&lt;Integer&gt; list = ...;  matches(figure,       Ranges.head(), (var h) -&gt; System.out.println(\"list head: \" + h),       Ranges.tail(), (var t) -&gt; System.out.println(\"list tail: \" + t),       Ranges.empty() ()      -&gt; System.out.println(\"Empty value\"),       Else.class,    ()      -&gt; System.out.println(\"Default value\") );   <\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import static org.kl.pattern.CommonPattern.with; import static org.kl.pattern.CommonPattern.when;  Rectangle rect = new Rectangle();  with(rect, it -&gt; {        it.setWidth(5);        it.setHeight(10); });  when(        side == Side.LEFT,  () -&gt; System.out.println(\"left  value\"),        side == Side.RIGHT, () -&gt; System.out.println(\"right value\") );<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c pattern matching \u0441\u0438\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043b\u044f\u043c\u0431\u0434\u044b-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0432\u044b\u0432\u043e\u0434 \u0442\u0438\u043f\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043b\u044f\u043c\u0431\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 pattern matching \u0441\u0430\u043c\u044b\u043c\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0442 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043d\u0430 <a href=\"https:\/\/github.com\/klappdev\/jpml\">github<\/a>.<\/p>\n<\/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\/460773\/\"> https:\/\/habr.com\/ru\/post\/460773\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c (pattern matching) \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u044f\u0437\u044b\u043a\u0430. Java \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 pattern matching, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u0434\u044b \u0447\u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0432\u0441\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u043f\u0435\u0440\u0435\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u0435\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c. <\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Java 8, \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 pattern matching \u0432 \u0432\u0438\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0442\u0430\u043a \u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p><i><b>Constant pattern<\/b><\/i> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u0441 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438. \u0412 Java switch \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u0430, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0440\u043e\u043a\u0438. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430 \u0440\u0430\u0432\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0442\u043e\u0434 equals().<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">switch (data) {       case new Person(\"man\")    -&gt; System.out.println(\"man\");       case new Person(\"woman\")  -&gt; System.out.println(\"woman\");       case new Person(\"child\")  -&gt; System.out.println(\"child\");               case null                 -&gt; System.out.println(\"Null value \");       default                   -&gt; System.out.println(\"Default value: \" + data); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 6 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import org.kl.state.Else; import org.kl.state.Null; import static org.kl.pattern.ConstantPattern.matches;  matches(data,       new Person(\"man\"),    () -&gt;  System.out.println(\"man\");       new Person(\"woman\"),  () -&gt;  System.out.println(\"woman\");       new Person(\"child\"),  () -&gt;  System.out.println(\"child\");               Null.class,           () -&gt;  System.out.println(\"Null value \"),       Else.class,           () -&gt;  System.out.println(\"Default value: \" + data) );<\/code><\/pre>\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-292340","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292340","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=292340"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292340\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}