{"id":474923,"date":"2025-09-13T21:00:34","date_gmt":"2025-09-13T21:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=474923"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=474923","title":{"rendered":"<span>JEP 502 \u2014 Stable Values. \u041d\u043e\u0432\u0430\u044f \u0444\u0438\u0447\u0430 \u0438\u0437 Java 25<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c (<a href=\"https:\/\/softwaremill.com\/jep-502-stable-values-new-feature-of-java-25-explained\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/a>) \u0437\u0430 \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u043e\u043c <a href=\"https:\/\/softwaremill.com\/blog\/?author=Sebastian%20Rabiej\" rel=\"noopener noreferrer nofollow\">Sebastian Rabiej<\/a><\/p>\n<hr\/>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <strong>JEP 502 \u2014 Stable Values<\/strong>. \u042d\u0442\u043e \u043d\u043e\u0432\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 <strong>Java 25<\/strong> \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c LTS-\u0440\u0435\u043b\u0438\u0437\u0435, \u043d\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u044c. \u0424\u0438\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a <strong>\u043f\u0435\u0440\u0432\u0430\u044f preview-\u0432\u0435\u0440\u0441\u0438\u044f<\/strong>, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. <\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Stable Value? <\/h2>\n<p><code>StableValue&lt;T&gt;<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 <strong>\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong> \u0442\u0438\u043f\u0430 <code>T<\/code>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c<\/strong>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u00ab\u0432 \u0438\u0442\u043e\u0433\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0449\u0435\u043c\u0441\u044f <code>final<\/code>\u00bb &#8212; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (eventually final).<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e: <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442<\/strong>. \u0421\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434 \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u0414\u043e Stable Values<\/h2>\n<p>\u0414\u043e Java 25, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>final<\/code>:  <\/p>\n<pre><code class=\"java\">class Controller {   private final EmailSender sender = new EmailSender(); }<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <code>final<\/code>-\u043f\u043e\u043b\u0435, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>\u0437\u0430\u0440\u0430\u043d\u0435\u0435<\/strong> \u2014 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438\u043b\u0438 \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e <strong>\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c\u0441\u044f: \u0432\u0435\u0434\u044c \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u043d\u0443\u0436\u043d\u044b \u0441\u0440\u0430\u0437\u0443, \u0432\u0435\u0440\u043d\u043e?<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c <code>final<\/code> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">class PetClinicController {    private EmailSender sender = null;      EmailSender getSender() {     if (sender == null) {       sender = new EmailSender();     }     return sender;   }    void adoptPet(User user, Pet pet) {     \/\/ some logic here     getSender().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041d\u043e \u0437\u0430 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><code>sender<\/code> \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <strong>\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c<\/strong> \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0435\u043c\u0443 \u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b\/\u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u043e\u0434-\u0440\u0435\u0432\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0438\u0441\u043a <code><strong>NullPointerException<\/strong><\/code>, \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u0442\u0442\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u0442\u0442\u0435\u0440 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0443\u0447\u0435\u0441\u0442\u044c, \u043c\u044b \u043c\u0435\u0448\u0430\u0435\u043c JVM <strong>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f<\/strong> \u043a \u043f\u043e\u043b\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u0440\u0435\u0437 constant-folding).<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 Stable Values  <\/h2>\n<p>\u0412\u043e\u0437\u044c\u043c\u0451\u043c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0451\u043c \u0435\u0433\u043e \u043d\u0430 \u043d\u043e\u0432\u0443\u044e Java 25: <\/p>\n<pre><code class=\"java\">class PetClinicController {    private final StableValue&lt;EmailSender&gt; sender = StableValue.of();    EmailSender getSender() {     return sender.orElseSet(() -&gt; new EmailSender());   }    void adoptPet(User user, Pet pet) {     \/\/ some logic here     getSender().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436, \u043d\u043e <code>StableValue<\/code> \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f <strong>\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 null-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c<\/strong> \u0434\u043b\u044f <code>EmailSender<\/code>. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>EmailSender<\/code>, \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0432 \u043f\u0440\u0435\u0436\u0434\u0435 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 <code>StableValue<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e<\/strong>.<\/p>\n<h2>Stable-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p><code>StableValue<\/code> \u0441\u043b\u0443\u0436\u0438\u0442 \u0431\u0430\u0437\u043e\u0439 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. \u0421\u0435\u0439\u0447\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 <strong>stable-\u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/strong>.<\/p>\n<p><code><strong>Supplier<\/strong><\/code><\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f <strong>\u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437<\/strong>, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u0445. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:<\/p>\n<pre><code class=\"java\">class PetClinicController {    private Supplier&lt;EmailSender&gt; sender = StableValue.supplier(() -&gt; new EmailSender());    void adoptPet(User user, Pet pet) {     \/\/ some logic here     sender.get().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p><code><strong>intFunction<\/strong><\/code> <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>int<\/code> \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c <strong>\u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/strong> \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u041f\u043e\u043b\u0435\u0437\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. <\/p>\n<pre><code class=\"java\">private final int SIZE = 3; private final IntFunction&lt;Integer&gt; INT_FUNCTION = v -&gt; {   \/\/ Simulate expensive computation   log(\"Computing value for: \" + v);   return 42; };  private void runIntFunction() {   var integerIntFunction = StableValue.intFunction(SIZE, INT_FUNCTION);    log(integerIntFunction.apply(1));   log(integerIntFunction.apply(1));   log(integerIntFunction.apply(1));    log(integerIntFunction.apply(2)); }<\/code><\/pre>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>runIntFunction<\/code>:  <\/p>\n<pre><code class=\"css\">Computing value for: 1 Value: 42 Value: 42 Value: 42 Computing value for: 2 Value: 42<\/code><\/pre>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>size<\/code>: <strong>\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u0445\u043e\u0434\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435<\/strong>. \u0415\u0441\u043b\u0438 \u0432\u044b\u0439\u0442\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 3), \u0431\u0443\u0434\u0435\u0442 <strong>runtime-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/strong>: <code>Input not allowed: 3<\/code>. <\/p>\n<p><code><strong>Function<\/strong><\/code> <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>intFunction<\/code>: \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0447\u0435\u043c \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<pre><code class=\"java\">private Set&lt;Color&gt; KEYS = Set.of(Color.GRAY, Color.GOLDEN); private Function&lt;Color, HowCute&gt; CUTE_FUNCTION = color -&gt; {   System.out.println(\"Computing cuteness for: \" + color);   return switch (color) {     case RED -&gt; HowCute.CUTE;     case GRAY -&gt; HowCute.VERY_CUTE;     case GOLDEN -&gt; HowCute.SUPER_CUTE;   }; };  private void runCuteFunction() {   var cuteFunction = StableValue.function(KEYS, CUTE_FUNCTION);    log(cuteFunction.apply(Color.GOLDEN));   log(cuteFunction.apply(Color.GOLDEN));   log(cuteFunction.apply(Color.GOLDEN));    log(cuteFunction.apply(Color.GRAY));    log(cuteFunction.apply(Color.RED)); }<\/code><\/pre>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<pre><code class=\"css\">Computing cuteness for: GOLDEN Value: SUPER_CUTE Value: SUPER_CUTE Value: SUPER_CUTE Computing cuteness for: GRAY Value: VERY_CUTE Exception in thread \"main\" java.lang.IllegalArgumentException: Input not allowed: RED<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>\u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0443\u043c\u0435\u0435\u0442<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u0432\u0445\u043e\u0434\u043e\u043c, \u043d\u043e \u043e\u043d <strong>\u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d<\/strong> \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 <code>inputs<\/code>, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>Input not allowed<\/code>. <\/p>\n<h2>Stable-\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438  <\/h2>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/strong> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e <code>StableValue<\/code>. \u041f\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e <code>List<\/code> \u0438 <code>Map<\/code>.<\/p>\n<pre><code class=\"java\">List&lt;Integer&gt; list = StableValue.list(SIZE, INT_FUNCTION); Map&lt;Color, HowCute&gt; map = StableValue.map(KEYS, CUTE_FUNCTION);<\/code><\/pre>\n<p>\u0418\u0437 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <code>StableFunction<\/code> \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e <code>intFunction<\/code>.<\/p>\n<h2>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b  <\/h2>\n<p>Stable Values \u043f\u0440\u043e\u0441\u0442\u044b \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b, \u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u044f\u0445.<\/p>\n<p><code><strong>Serializable<\/strong><\/code><br \/><code>StableValue<\/code> <strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> <code>Serializable<\/code>. \u0412 \u0441\u0430\u043c\u043e\u043c JEP \u044d\u0442\u043e \u043d\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e, \u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/cr.openjdk.org\/~pminborg\/stable-values2\/api\/java.base\/java\/lang\/StableValue.html#performance\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u0415\u0441\u043b\u0438 \u0432\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 <code>final<\/code> \u043d\u0430 <code>StableValue<\/code>, \u0442\u0443\u0442 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p><strong>\u0411\u0435\u0437 <\/strong><code><strong>final<\/strong><\/code><br \/>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>StableValue<\/code>, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c <strong>\u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong>. \u041d\u0438\u0447\u0442\u043e (\u043a\u0440\u043e\u043c\u0435 \u0437\u0434\u0440\u0430\u0432\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430) \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">private StableValue&lt;EmailSender&gt; sender = StableValue.of(); void adoptPet(User user, Pet pet) {   sender = null;   \/\/ some logic here   sender.orElseSet(...) \/\/ Null pointer exception }<\/code><\/pre>\n<p>\u041b\u0443\u0447\u0448\u0435 \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f <code>StableValue<\/code> \u043a\u0430\u043a <code><strong>final<\/strong><\/code>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0438 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 <code>Optional&lt;&gt;<\/code>.<\/p>\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u0432\u0432\u0435\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u2014 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <code>Lazy<\/code>, \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445? \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044e JEP.<\/p>\n<h2>\u041a\u0430\u043a\u043e\u0432\u0430 \u0446\u0435\u043b\u044c JEP? <\/h2>\n<p>\u0418\u0437 JEP \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0446\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u2014 <strong>\u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a Java-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/strong>, \u043e\u0442\u0434\u0435\u043b\u0438\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u00ab\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u0438 \u0434\u0430\u0442\u044c JVM \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 <strong>constant-folding<\/strong>.<\/p>\n<p>\u041e\u043d\u0438 <strong>\u043d\u0435 \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u044f\u0437\u044b\u043a Java \u043d\u043e\u0432\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u00ab\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 <code>final<\/code>-\u043f\u043e\u043b\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e, \u0445\u043e\u0442\u044f \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u00ab<code>Lazy<\/code>\u00bb, \u044f \u0440\u0430\u0434 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 <strong>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434<\/strong>. \u0421 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043d\u0438\u0435\u043c \u0436\u0434\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<hr\/>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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\/articles\/946682\/\"> https:\/\/habr.com\/ru\/articles\/946682\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c (<a href=\"https:\/\/softwaremill.com\/jep-502-stable-values-new-feature-of-java-25-explained\/\" rel=\"noopener noreferrer nofollow\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/a>) \u0437\u0430 \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u043e\u043c <a href=\"https:\/\/softwaremill.com\/blog\/?author=Sebastian%20Rabiej\" rel=\"noopener noreferrer nofollow\">Sebastian Rabiej<\/a><\/p>\n<hr\/>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <strong>JEP 502 \u2014 Stable Values<\/strong>. \u042d\u0442\u043e \u043d\u043e\u0432\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 <strong>Java 25<\/strong> \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c LTS-\u0440\u0435\u043b\u0438\u0437\u0435, \u043d\u0430\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u043c \u043d\u0430 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u044c. \u0424\u0438\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a <strong>\u043f\u0435\u0440\u0432\u0430\u044f preview-\u0432\u0435\u0440\u0441\u0438\u044f<\/strong>, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f. <\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Stable Value? <\/h2>\n<p><code>StableValue&lt;T&gt;<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 <strong>\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong> \u0442\u0438\u043f\u0430 <code>T<\/code>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c<\/strong>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u00ab\u0432 \u0438\u0442\u043e\u0433\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0449\u0435\u043c\u0441\u044f <code>final<\/code>\u00bb &#8212; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (eventually final).<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e: <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442<\/strong>. \u0421\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434 \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u0414\u043e Stable Values<\/h2>\n<p>\u0414\u043e Java 25, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>final<\/code>:  <\/p>\n<pre><code class=\"java\">class Controller {   private final EmailSender sender = new EmailSender(); }<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <code>final<\/code>-\u043f\u043e\u043b\u0435, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>\u0437\u0430\u0440\u0430\u043d\u0435\u0435<\/strong> \u2014 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0438\u043b\u0438 \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e <strong>\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c\u0441\u044f: \u0432\u0435\u0434\u044c \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u043d\u0443\u0436\u043d\u044b \u0441\u0440\u0430\u0437\u0443, \u0432\u0435\u0440\u043d\u043e?<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c <code>final<\/code> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">class PetClinicController {    private EmailSender sender = null;      EmailSender getSender() {     if (sender == null) {       sender = new EmailSender();     }     return sender;   }    void adoptPet(User user, Pet pet) {     \/\/ some logic here     getSender().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041d\u043e \u0437\u0430 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><code>sender<\/code> \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f <strong>\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c<\/strong> \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0435\u043c\u0443 \u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b\/\u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u043e\u0434-\u0440\u0435\u0432\u044c\u044e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0438\u0441\u043a <code><strong>NullPointerException<\/strong><\/code>, \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0433\u0435\u0442\u0442\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u0442\u0442\u0435\u0440 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u0441\u0451 \u0443\u0447\u0435\u0441\u0442\u044c, \u043c\u044b \u043c\u0435\u0448\u0430\u0435\u043c JVM <strong>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f<\/strong> \u043a \u043f\u043e\u043b\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0435\u0440\u0435\u0437 constant-folding).<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 Stable Values  <\/h2>\n<p>\u0412\u043e\u0437\u044c\u043c\u0451\u043c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0451\u043c \u0435\u0433\u043e \u043d\u0430 \u043d\u043e\u0432\u0443\u044e Java 25: <\/p>\n<pre><code class=\"java\">class PetClinicController {    private final StableValue&lt;EmailSender&gt; sender = StableValue.of();    EmailSender getSender() {     return sender.orElseSet(() -&gt; new EmailSender());   }    void adoptPet(User user, Pet pet) {     \/\/ some logic here     getSender().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436, \u043d\u043e <code>StableValue<\/code> \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f <strong>\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 null-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c<\/strong> \u0434\u043b\u044f <code>EmailSender<\/code>. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>EmailSender<\/code>, \u043d\u0435 \u0432\u044b\u0437\u0432\u0430\u0432 \u043f\u0440\u0435\u0436\u0434\u0435 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 <code>StableValue<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e<\/strong>.<\/p>\n<h2>Stable-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p><code>StableValue<\/code> \u0441\u043b\u0443\u0436\u0438\u0442 \u0431\u0430\u0437\u043e\u0439 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. \u0421\u0435\u0439\u0447\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 <strong>stable-\u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/strong>.<\/p>\n<p><code><strong>Supplier<\/strong><\/code><\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f <strong>\u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437<\/strong>, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u0445. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:<\/p>\n<pre><code class=\"java\">class PetClinicController {    private Supplier&lt;EmailSender&gt; sender = StableValue.supplier(() -&gt; new EmailSender());    void adoptPet(User user, Pet pet) {     \/\/ some logic here     sender.get().sendEmailTo(user, \"You are great person!\");   } }<\/code><\/pre>\n<p><code><strong>intFunction<\/strong><\/code> <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>int<\/code> \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0435\u043c <strong>\u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/strong> \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430. \u041f\u043e\u043b\u0435\u0437\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. <\/p>\n<pre><code class=\"java\">private final int SIZE = 3; private final IntFunction&lt;Integer&gt; INT_FUNCTION = v -&gt; {   \/\/ Simulate expensive computation   log(\"Computing value for: \" + v);   return 42; };  private void runIntFunction() {   var integerIntFunction = StableValue.intFunction(SIZE, INT_FUNCTION);    log(integerIntFunction.apply(1));   log(integerIntFunction.apply(1));   log(integerIntFunction.apply(1));    log(integerIntFunction.apply(2)); }<\/code><\/pre>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 <code>runIntFunction<\/code>:  <\/p>\n<pre><code class=\"css\">Computing value for: 1 Value: 42 Value: 42 Value: 42 Computing value for: 2 Value: 42<\/code><\/pre>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>size<\/code>: <strong>\u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0432\u0445\u043e\u0434\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435<\/strong>. \u0415\u0441\u043b\u0438 \u0432\u044b\u0439\u0442\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 3), \u0431\u0443\u0434\u0435\u0442 <strong>runtime-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/strong>: <code>Input not allowed: 3<\/code>. <\/p>\n<p><code><strong>Function<\/strong><\/code> <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>intFunction<\/code>: \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0447\u0435\u043c \u0443\u0433\u043e\u0434\u043d\u043e.<\/p>\n<pre><code class=\"java\">private Set&lt;Color&gt; KEYS = Set.of(Color.GRAY, Color.GOLDEN); private Function&lt;Color, HowCute&gt; CUTE_FUNCTION = color -&gt; {   System.out.println(\"Computing cuteness for: \" + color);   return switch (color) {     case RED -&gt; HowCute.CUTE;     case GRAY -&gt; HowCute.VERY_CUTE;     case GOLDEN -&gt; HowCute.SUPER_CUTE;   }; };  private void runCuteFunction() {   var cuteFunction = StableValue.function(KEYS, CUTE_FUNCTION);    log(cuteFunction.apply(Color.GOLDEN));   log(cuteFunction.apply(Color.GOLDEN));   log(cuteFunction.apply(Color.GOLDEN));    log(cuteFunction.apply(Color.GRAY));    log(cuteFunction.apply(Color.RED)); }<\/code><\/pre>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<pre><code class=\"css\">Computing cuteness for: GOLDEN Value: SUPER_CUTE Value: SUPER_CUTE Value: SUPER_CUTE Computing cuteness for: GRAY Value: VERY_CUTE Exception in thread \"main\" java.lang.IllegalArgumentException: Input not allowed: RED<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>\u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0443\u043c\u0435\u0435\u0442<\/strong> \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c \u0432\u0445\u043e\u0434\u043e\u043c, \u043d\u043e \u043e\u043d <strong>\u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d<\/strong> \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 <code>inputs<\/code>, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>Input not allowed<\/code>. <\/p>\n<h2>Stable-\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438  <\/h2>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/strong> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e <code>StableValue<\/code>. \u041f\u043e\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e <code>List<\/code> \u0438 <code>Map<\/code>.<\/p>\n<pre><code class=\"java\">List&lt;Integer&gt; list = StableValue.list(SIZE, INT_FUNCTION); Map&lt;Color, HowCute&gt; map = StableValue.map(KEYS, CUTE_FUNCTION);<\/code><\/pre>\n<p>\u0418\u0437 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f <code>StableFunction<\/code> \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0442\u043e\u043b\u044c\u043a\u043e <code>intFunction<\/code>.<\/p>\n<h2>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b  <\/h2>\n<p>Stable Values \u043f\u0440\u043e\u0441\u0442\u044b \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b, \u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u043e \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0445 \u043a\u0430\u043c\u043d\u044f\u0445.<\/p>\n<p><code><strong>Serializable<\/strong><\/code><br \/><code>StableValue<\/code> <strong>\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/strong> <code>Serializable<\/code>. \u0412 \u0441\u0430\u043c\u043e\u043c JEP \u044d\u0442\u043e \u043d\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e, \u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/cr.openjdk.org\/~pminborg\/stable-values2\/api\/java.base\/java\/lang\/StableValue.html#performance\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u0415\u0441\u043b\u0438 \u0432\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 <code>final<\/code> \u043d\u0430 <code>StableValue<\/code>, \u0442\u0443\u0442 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p><strong>\u0411\u0435\u0437 <\/strong><code><strong>final<\/strong><\/code><br \/>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>StableValue<\/code>, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c <strong>\u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/strong>. \u041d\u0438\u0447\u0442\u043e (\u043a\u0440\u043e\u043c\u0435 \u0437\u0434\u0440\u0430\u0432\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430) \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">private StableValue&lt;EmailSender&gt; sender = StableValue.of(); void adoptPet(User user, Pet pet) {   sender = null;   \/\/ some logic here   sender.orElseSet(...) \/\/ Null pointer exception }<\/code><\/pre>\n<p>\u041b\u0443\u0447\u0448\u0435 \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f <code>StableValue<\/code> \u043a\u0430\u043a <code><strong>final<\/strong><\/code>, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0438 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 <code>Optional&lt;&gt;<\/code>.<\/p>\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u0432\u0432\u0435\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u2014 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <code>Lazy<\/code>, \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445? \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044e JEP.<\/p>\n<h2>\u041a\u0430\u043a\u043e\u0432\u0430 \u0446\u0435\u043b\u044c JEP? <\/h2>\n<p>\u0418\u0437 JEP \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0446\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u2014 <strong>\u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a Java-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439<\/strong>, \u043e\u0442\u0434\u0435\u043b\u0438\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u00ab\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u0438 \u0434\u0430\u0442\u044c JVM \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 <strong>constant-folding<\/strong>.<\/p>\n<p>\u041e\u043d\u0438 <strong>\u043d\u0435 \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u044f\u0437\u044b\u043a Java \u043d\u043e\u0432\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u00ab\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0445\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439;<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 <code>final<\/code>-\u043f\u043e\u043b\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e, \u0445\u043e\u0442\u044f \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u00ab<code>Lazy<\/code>\u00bb, \u044f \u0440\u0430\u0434 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 <strong>\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434<\/strong>. \u0421 \u043d\u0435\u0442\u0435\u0440\u043f\u0435\u043d\u0438\u0435\u043c \u0436\u0434\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<hr\/>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><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\/articles\/946682\/\"> https:\/\/habr.com\/ru\/articles\/946682\/<\/a><br \/><\/br><\/br><\/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-474923","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474923","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=474923"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474923\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}