{"id":866,"date":"2025-08-31T13:59:52","date_gmt":"2025-08-31T13:59:52","guid":{"rendered":"https:\/\/nurlandroid.com\/?p=866"},"modified":"2025-08-31T13:59:53","modified_gmt":"2025-08-31T13:59:53","slug":"init-%d0%b2-kotlin-%d1%8d%d1%82%d0%be-%d0%b0%d0%bd%d0%b0%d0%bb%d0%be%d0%b3-%d1%87%d0%b5%d0%b3%d0%be-%d0%b2-java","status":"publish","type":"post","link":"https:\/\/nurlandroid.com\/?p=866","title":{"rendered":"init{} \u0432 Kotlin \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u0447\u0435\u0433\u043e \u0432 Java?"},"content":{"rendered":"\n<p><code>init {}<\/code> \u0432 Kotlin \u2014 \u044d\u0442\u043e <strong>\u0431\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/strong>, \u0438 \u0435\u0433\u043e <strong>\u0430\u043d\u0430\u043b\u043e\u0433 \u0432 Java<\/strong> \u2014 \u044d\u0442\u043e <strong>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430<\/strong> (instance initializer block).<\/p>\n\n\n\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 Kotlin:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Person(val name: String) {\n    init {\n        println(&quot;Init block: $name&quot;)\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u0410\u043d\u0430\u043b\u043e\u0433 \u0432 Java:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npublic class Person {\n    private final String name;\n\n    {\n        System.out.println(&quot;Init block: &quot; + name);\n    }\n\n    public Person(String name) {\n        this.name = name;\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u041e\u0431\u0440\u0430\u0442\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>init {}<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <strong>\u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430<\/strong>, <strong>\u0434\u043e \u0442\u0435\u043b\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/strong><\/li>\n\n\n\n<li>\u0432 Java \u044d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>&#171;instance initializer block&#187;<\/strong> \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <strong>\u0434\u043e \u0442\u0435\u043b\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/strong><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u042d\u0442\u0430\u043f<\/th><th>Kotlin (<code>init {}<\/code>)<\/th><th>Java<\/th><\/tr><\/thead><tbody><tr><td>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f<\/td><td>\u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>primary constructor<\/code><\/td><td>\u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043b\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/td><\/tr><tr><td>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e?<\/td><td>\u0414\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f<\/td><td>\u0414\u0430<\/td><\/tr><tr><td>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430<\/td><td>\u0414\u0430<\/td><td>\u0414\u0430<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>init {} \u0432 Kotlin \u2014 \u044d\u0442\u043e \u0431\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438 \u0435\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433 \u0432 Java \u2014 \u044d\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 (instance initializer block). \u041f\u0440\u0438\u043c\u0435\u0440 Kotlin: \u0410\u043d\u0430\u043b\u043e\u0433 \u0432 Java: \u041e\u0431\u0440\u0430\u0442\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u042d\u0442\u0430\u043f Kotlin (init {}) Java \u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 primary constructor \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043b\u043e\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e? \u0414\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0414\u0430 \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,31],"tags":[],"class_list":["post-866","post","type-post","status-publish","format-standard","hentry","category-kotlin","category-questions"],"_links":{"self":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=866"}],"version-history":[{"count":1,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/866\/revisions"}],"predecessor-version":[{"id":867,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=\/wp\/v2\/posts\/866\/revisions\/867"}],"wp:attachment":[{"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nurlandroid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}