{"id":349073,"date":"2023-06-20T09:06:10","date_gmt":"2023-06-20T09:06:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349073"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349073","title":{"rendered":"<span>\u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 Scala<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u041c\u0443\u043b\u043b\u043e, \u044f \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u0413\u0440\u0443\u043f\u043f\u044b \u00ab\u0418\u043d\u043d\u043e\u0442\u0435\u0445\u00bb.<br \/>\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0\u043d\u0430 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f\u00a0\u043f\u043e\u043d\u044f\u0442\u0438\u044f\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f,\u00a0\u0442\u0430\u043a\u0438\u0435\u00a0\u043a\u0430\u043a\u00a0\u00ab\u043a\u043b\u0430\u0441\u0441\u00bb\u00a0\u0438\u00a0\u00ab\u043e\u0431\u044a\u0435\u043a\u0442\u00bb, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0435\u00a0\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u044f\u0437\u044b\u043a\u0430 Scala \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u00ab\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u044f\u0437\u044b\u043a\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043d\u0430 Scala \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0443\u043f\u0435\u0440\u0441\u0438\u043b\u044b \u044f\u0437\u044b\u043a\u0430 &#8212; \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u00ab\u043b\u0438\u0448\u043d\u0438\u043c\u0438\u00bb \u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438, \u0443\u0445\u0443\u0434\u0448\u0430\u044e\u0449\u0438\u043c\u0438 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c. \u041d\u0430 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Apache Spark, \u043e\u0434\u0438\u043d \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u0442\u0430-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0442\u0438\u043f\u043e\u0432 \u0432 Scala \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Int<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0410 \u0441\u0430\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Int<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <code>+<\/code> \u0438 <code>-<\/code>.<\/p>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 Scala 2.12.<\/p>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/h3>\n<p>\u0412 Scala \u043a\u043b\u0430\u0441\u0441 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <em>class<\/em>.<\/p>\n<pre><code class=\"scala\">class Empty { \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Empty   \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430 }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/p>\n<\/li>\n<li>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"scala\">class Counter {              \/\/ \u043a\u043b\u0430\u0441\u0441 Counter \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432   val x: Int = 0             \/\/ val-\u043f\u043e\u043b\u0435      def this(y: Int) = {       \/\/ \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     this()                   \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430     x + y   }      def increment(): Unit = {  \/\/ \u043c\u0435\u0442\u043e\u0434 increment     x + 1   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u00a0<em>new<\/em>:<\/p>\n<pre><code class=\"scala\">val c = new Counter \/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Counter c.increment()       \/\/ \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 increment<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u044b\u0432\u043e\u0434, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"bash\">defined class Counter c: Counter = Counter@4d85a26a<\/code><\/pre>\n<p>\u041a\u0430\u043a\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 0 \u0438 1, \u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430?<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> &#8212; \u0443\u0431\u0435\u0440\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>x<\/code>:<\/p>\n<pre><code class=\"scala\">class Counter {   val x: Int = 0      def increment(): Unit = x = x + 1 }<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"scala\">val x: Int = 0 ... x = y \/\/ \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438: reassignment to val<\/code><\/pre>\n<blockquote>\n<p><strong>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e val- \u0438 var-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/strong><br \/>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Scala \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430\u00a0<em>val<\/em>\u00a0\u0438\u00a0<em>var<\/em>, \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<\/p>\n<p>\/\/ var-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f x<br \/>var x = 0<\/p>\n<p>\/\/ val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f msg<br \/>val msg = &#171;Hi&#187;<\/p>\n<p>\/\/ val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f y<br \/>val y = x + 1<\/p>\n<p>\/\/ \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c<br \/>\/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 msg<br \/>println(msg)<\/p>\n<\/p>\n<p>\/\/ \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<br \/>\/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f<br \/>msg = &#171;Bye&#187;<br \/>\/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f<br \/>y = -1<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0435 \u0442\u0438\u043f:\u00a0<code>val roundPi: Double = 3.14<\/code>. \u0421\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0443 Scala \u043c\u043e\u0449\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u043f\u043e\u043b\u0435 <code>x<\/code>:<\/p>\n<pre><code class=\"scala\">class Counter {   var x: Int = 0      def increment(): Unit = x = x + 1 }  val counter = new Counter counter.increment() counter.increment() counter.increment() println(counter.x) \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 3<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e\u00a0<em>x<\/em>\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u00ab\u0442\u043e\u0447\u043a\u0430\u00bb:\u00a0<code>c.increment()<\/code>,\u00a0<code>c.x<\/code>.<\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f\u00a0<code>x<\/code>:\u00a0<code>counter.x = 100<\/code>? \u042d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u00a0<code>counter<\/code>:<\/p>\n<pre><code class=\"scala\">counter.increment() \/\/ 1 counter.increment() \/\/ 2 \/\/ ... \u0437\u0434\u0435\u0441\u044c \u0435\u0449\u0435 \u043a\u043e\u0434 \/\/ counter.x = -10 \/\/ ... \u0437\u0434\u0435\u0441\u044c \u0435\u0449\u0435 \u043a\u043e\u0434 if (counter.x > 0) {   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 counter.x \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e   \/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f counter.x   ... }<\/code><\/pre>\n<p>\u041d\u0443\u0436\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e <code>counter<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430:\u00a0<em>private<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u0415\u0441\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d, \u0442\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<em>public<\/em>\u00a0&#8212; \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437\u0432\u043d\u0435.<\/p>\n<pre><code class=\"scala\">class Counter {   private var x: Int = 0      def increment(): Unit = x = x + 1 }  val counter = new Counter counter.increment() counter.increment() println(counter.x)  \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:                     \/\/ variable x in class Counter cannot be accessed in Counter<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0435 <code>x<\/code> \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0438\u0437\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u043d\u0443\u0436\u0435\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437\u0432\u043d\u0435, \u043d\u043e \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u0431\u044b \u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Counter<\/code> \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\u00a0<code>x<\/code>.<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _ \/\/ \u0438\u043b\u0438 \u044f\u0432\u043d\u043e: var _x: Int = 0      def x: Int = _x         \/\/ \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f      def increment(): Unit = _x = _x + 1 }  val counter = new Counter counter.increment() counter.increment() println(counter.x)  \/\/ \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 counter.x = 0       \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f: value x_= is not a member of Counter counter._x = 0      \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:                     \/\/ variable _x in class Counter cannot be accessed in Counter<\/code><\/pre>\n<p>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<em>def<\/em>\u00a0\u043e\u0442 \u00abdefinition\u00bb. \u041f\u043e\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438\u00a0<em>val<\/em>\u00a0\u0438\u00a0<em>var<\/em>\u00a0\u043e\u0442 \u00abvalue\u00bb \u0438 \u00abvariable\u00bb \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e. \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u00ab_\u00bb, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u00ab=\u00bb \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438:<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _      def x: Int = _x      private var _step: Int = 1        \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435                                     \/\/ \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e step \u044d\u0442\u043e \u043f\u0430\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:   def step: Int = _step             \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f      def step_=(value: Int): Unit = {  \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438     _step = value   }      def increment(): Unit = _x = _x + step }<\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 Scala \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _      def x: Int = _x      private var _step: Int = 1       \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435                                     \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f step \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442      def step_=(value: Int): Unit = { \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438     _step = value   }      def increment(): Unit = _x = _x + _step }  val counter = new Counter counter.step = 10 \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f: value step is not a member of Counter<\/code><\/pre>\n<p><strong>\u0412\u043e\u043f\u0440\u043e\u0441<\/strong>: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u0430\u043a\u00a0<code>var x: Int = _x<\/code>\u00a0\u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Counter<\/code>?<\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e &#8212; \u043d\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<em>def<\/em>, \u043d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b, \u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c.<\/p>\n<pre><code class=\"scala\">class Counter {   println(\"start main ctor\")      private var _x: Int = _      val x: Int = _x \/\/ \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442 x \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 _x \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b                   \/\/ \u043a \u043d\u0435\u043c\u0443 \u043d\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c      private var _step: Int = 1      def increment(): Unit = _x = _x + _step      println(\"end main ctor\") }  val counter = new Counter counter.increment() counter.increment() println(counter.x)<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code>defined class Counter start main ctor end main ctor counter: Counter = Counter@464b627c 0<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043c\u0435\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>Counter<\/code> \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432. \u0417\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043d\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<pre><code class=\"scala\">class Counter(private var _x: Int = 0) {  \/\/ \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c:                                           \/\/ Counter(Int)   def x: Int = _x      private var _step: Int = 1      def step: Int = _step      def step_=(value: Int): Unit = _step = value      def increment(): Unit = _x = _x + step }<\/code><\/pre>\n<p>\u0418\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (\u00abauxilliary\u00bb) \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"scala\">class Counter {  \/\/ \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:                  \/\/ Counter()   println(\"start main ctor\")      private var _x: Int = 0      def x: Int = _x      private var _step: Int = 1      def step: Int = _step      def step_=(value: Int): Unit = _step = value      def increment(): Unit = _x = _x + step      def this(initX: Int) = {  \/\/ \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: Counter(Int)     this()                  \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0432\u044b\u043c     println(\"start aux ctor 1\")     _x = initX     println(\"end aux ctor 1\")   }      def this(initX: Int, initStep: Int) = {  \/\/ \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: Counter(Int, Int)     this(initX)                            \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430,                                            \/\/ \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     println(\"start aux ctor 2\")     _step = initStep     println(\"end aux ctor 2\")   }      println(\"end main ctor\") }  val counter = new Counter(10, 2) counter.increment() println(counter.x)<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code class=\"bash\">defined class Counter start main ctor end main ctor start aux ctor 1 end aux ctor 1 start aux ctor 2 end aux ctor 2 counter: Counter = Counter@64d9850 12<\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443 \u0438\u0437\u0432\u043d\u0435? \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430\u00a0<em>private<\/em>:<\/p>\n<pre><code class=\"scala\">class Counter private(private var x: Int = 0) {   \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Counter }<\/code><\/pre>\n<p>\u0417\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"scala\">class Counter {   private def watchDog(): Unit = \/\/ ...      def increment(): Unit = {     watchDog()     \/\/ ...   } }<\/code><\/pre>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u0432 Scala \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"scala\">object Empty { \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Empty   \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430 }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430, \u0442\u043e \u043e\u043d\u043e \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043d\u043e \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u044b \u0441\u0432\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043d\u0435\u043c\u0443:<\/p>\n<pre><code class=\"scala\">class Counter private(_init: Int) {   println(\"Counter class ctor\")      private def show(): Unit = println(\"inside Counter class ctor\")      show()      private var _x: Int = _init      def current: Int = _x      def increment(step: Int = 1): Unit = {     _x = Counter.add(_x, step)   }      println(\"Counter class ctor END\") }  object Counter {   println(\"Counter object ctor\")      private def show(): Unit = println(\"inside Counter object ctor\")      show()      def apply(init: Int): Counter = {     new Counter(init)   }    private def add(a: Int, b: Int): Int = a + b      private def check(): Unit = {     require(add(1, 2) == 3,     \"\"\"       |ERROR!       |self check: 1 + 2 must be 3, but not today!       |\"\"\".stripMargin)     println(\"self check is OK\")   }      check()      println(\"Counter object ctor END\") }  val counter = Counter(100) \/\/ \"\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440\" \/\/ \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u0443 Counter.apply(100) \/\/ \u043f\u0440\u0438 \u043f\u0435\u0447\u0430\u0442\u0438 \u0432\u0438\u0434\u043d\u043e \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 counter.increment() counter.increment() counter.increment() println(counter.current) val another = Counter(200) \/\/ \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435\u0442 another.increment(2) another.increment(2) another.increment(2) println(another.current)<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"bash\">Counter object ctor inside Counter object ctor self check is OK Counter object ctor END Counter class ctor inside Counter class ctor Counter class ctor END counter: Counter = Counter@496c3c91 103 Counter class ctor inside Counter class ctor Counter class ctor END another: Counter = Counter@340823cf 206<\/code><\/pre>\n<h3>\u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 Java<\/h3>\n<p>Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> \u0438 \u0430\u043d\u0430\u043b\u043e\u0433 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"java\">class Counter {     private void show() {         System.out.println(\"inside Counter class ctor\");     }        private int x;                  \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435      private int getX() {            \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f         return x;     }      private void setX(int value) {  \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438         x = value;     }      public int current() {         return getX();     }      public void increment(int step) {         setX(CounterObject.add(getX(), step));     }      public void increment() {         setX(CounterObject.add(getX(), 1));     }      private Counter(int init) {  \/\/ \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432         System.out.println(\"Counter class ctor\");         show();         setX(init);         System.out.println(\"Counter class ctor END\");     }      \/**      * \u043e\u0434\u043d\u0430 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \"\u041e\u0434\u0438\u043d\u043e\u0447\u043a\u0430\" (Singleton)      *\/     static class CounterObject {         private static CounterObject instance;          private CounterObject() {         }          public static synchronized CounterObject getInstance() {             if (instance == null) {                 check();                 System.out.println(\"call ctor inside CounterObject.getInstance\");                 instance = new CounterObject();             }             return instance;         }          public Counter Counter(int init) {  \/\/ \u0430\u043d\u0430\u043b\u043e\u0433 Counter.apply(init: Int)             return new Counter(init);         }          private static int add(int a, int b) {             return a + b;         }          private static void check() {             assert add(1, 2) == 3 : \"ERROR! self check: 1 + 2 must be 3, but not today!\";         }     } }  class Main {     public static void main(String[] args) {         \/\/ \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Java         Counter.CounterObject cObj = Counter.CounterObject.getInstance();         Counter counter = cObj.Counter(100);  \/\/ \u043d\u0430 Scala: Counter(100)         counter.increment();         counter.increment();         counter.increment();         System.out.println(counter.current());         Counter another = cObj.Counter(200);  \/\/ \u043d\u0430 Scala: Counter(200)         another.increment(2);         another.increment(2);         another.increment(2);         System.out.println(another.current());     } }<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"bash\">call ctor inside CounterObject.getInstance Counter class ctor inside Counter class ctor Counter class ctor END 103 Counter class ctor inside Counter class ctor Counter class ctor END 206<\/code><\/pre>\n<p>\u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> \u043d\u0430 Scala, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u044b\u0432\u043e\u0434, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code class=\"bash\">> scalac Counter.scala > javap -private Counter Compiled from \"Counter.scala\" public class Counter {   private int _x;            \/\/ \u0432 \u043a\u043e\u0434\u0435: private var _x: Int   public static Counter apply(int);   private void show();   private int _x();          \/\/ \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440: def _x(): Int   private void _x_$eq(int);  \/\/ \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440: def _x_=(Int)   public int current();   public void increment(int);   public int increment$default$1();   public Counter(int); }<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u043a\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f\u00a0<code>_x<\/code>\u00a0\u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Counter<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>Counter<\/code> \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d, \u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u00ab$\u00bb:<\/p>\n<pre><code class=\"bash\">> javap -private Counter$ Compiled from \"Counter.scala\" public final class Counter$ {         \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 Counter$   \/\/ \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Counter$   \/\/ \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c: Counter$.MODULE$   public static final Counter$ MODULE$;   public static {};                   \/\/ \u0431\u043b\u043e\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438   private void show();   public Counter apply(int);   public int Counter$$add(int, int);   private void check();   private Counter$();                 \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Counter$ }<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 Scala \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 Java \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u0447\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Scala. \u0412 \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u043a\u0435 \u0432\u0438\u0434\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435\u00a0<code>MODULE$<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>Counter$<\/code>, \u0431\u043b\u043e\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u00a0<code>Counter$<\/code>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0441 Java, \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u044f\u0437\u044b\u043a\u0430 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. Scala \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0449\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f Java-\u043c\u0430\u0448\u0438\u043d\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430 Scala \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/p>\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\/companies\/innotech\/articles\/742606\/\"> https:\/\/habr.com\/ru\/companies\/innotech\/articles\/742606\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u041c\u0443\u043b\u043b\u043e, \u044f \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u0413\u0440\u0443\u043f\u043f\u044b \u00ab\u0418\u043d\u043d\u043e\u0442\u0435\u0445\u00bb.<br \/>\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0\u043d\u0430 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f\u00a0\u043f\u043e\u043d\u044f\u0442\u0438\u044f\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f,\u00a0\u0442\u0430\u043a\u0438\u0435\u00a0\u043a\u0430\u043a\u00a0\u00ab\u043a\u043b\u0430\u0441\u0441\u00bb\u00a0\u0438\u00a0\u00ab\u043e\u0431\u044a\u0435\u043a\u0442\u00bb, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0435\u00a0\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u044f\u0437\u044b\u043a\u0430 Scala \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u00ab\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u044f\u0437\u044b\u043a\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u0443 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043d\u0430 Scala \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0440\u0443\u043f\u043d\u044b\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0443\u043f\u0435\u0440\u0441\u0438\u043b\u044b \u044f\u0437\u044b\u043a\u0430 &#8212; \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u00ab\u043b\u0438\u0448\u043d\u0438\u043c\u0438\u00bb \u0434\u0435\u0442\u0430\u043b\u044f\u043c\u0438, \u0443\u0445\u0443\u0434\u0448\u0430\u044e\u0449\u0438\u043c\u0438 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c. \u041d\u0430 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Apache Spark, \u043e\u0434\u0438\u043d \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u0442\u0430-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430.<\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0442\u0438\u043f\u043e\u0432 \u0432 Scala \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Int<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043d\u0430\u0434 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0410 \u0441\u0430\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Int<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <code>+<\/code> \u0438 <code>-<\/code>.<\/p>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 Scala 2.12.<\/p>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/h3>\n<p>\u0412 Scala \u043a\u043b\u0430\u0441\u0441 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <em>class<\/em>.<\/p>\n<pre><code class=\"scala\">class Empty { \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Empty   \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430 }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e<\/p>\n<\/li>\n<li>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"scala\">class Counter {              \/\/ \u043a\u043b\u0430\u0441\u0441 Counter \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432   val x: Int = 0             \/\/ val-\u043f\u043e\u043b\u0435      def this(y: Int) = {       \/\/ \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     this()                   \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430     x + y   }      def increment(): Unit = {  \/\/ \u043c\u0435\u0442\u043e\u0434 increment     x + 1   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u00a0<em>new<\/em>:<\/p>\n<pre><code class=\"scala\">val c = new Counter \/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Counter c.increment()       \/\/ \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 increment<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u044b\u0432\u043e\u0434, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"bash\">defined class Counter c: Counter = Counter@4d85a26a<\/code><\/pre>\n<p>\u041a\u0430\u043a\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 0 \u0438 1, \u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430?<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> &#8212; \u0443\u0431\u0435\u0440\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f <code>x<\/code>:<\/p>\n<pre><code class=\"scala\">class Counter {   val x: Int = 0      def increment(): Unit = x = x + 1 }<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"scala\">val x: Int = 0 ... x = y \/\/ \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438: reassignment to val<\/code><\/pre>\n<blockquote>\n<p><strong>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e val- \u0438 var-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/strong><br \/>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Scala \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430\u00a0<em>val<\/em>\u00a0\u0438\u00a0<em>var<\/em>, \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<\/p>\n<p>\/\/ var-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f x<br \/>var x = 0<\/p>\n<p>\/\/ val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f msg<br \/>val msg = &#171;Hi&#187;<\/p>\n<p>\/\/ val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f y<br \/>val y = x + 1<\/p>\n<p>\/\/ \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c<br \/>\/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 msg<br \/>println(msg)<\/p>\n<\/p>\n<p>\/\/ \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f val-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<br \/>\/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f<br \/>msg = &#171;Bye&#187;<br \/>\/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f<br \/>y = -1<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0435 \u0442\u0438\u043f:\u00a0<code>val roundPi: Double = 3.14<\/code>. \u0421\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0443 Scala \u043c\u043e\u0449\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>Counter<\/code> &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u043f\u043e\u043b\u0435 <code>x<\/code>:<\/p>\n<pre><code class=\"scala\">class Counter {   var x: Int = 0      def increment(): Unit = x = x + 1 }  val counter = new Counter counter.increment() counter.increment() counter.increment() println(counter.x) \/\/ \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 3<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e\u00a0<em>x<\/em>\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u00ab\u0442\u043e\u0447\u043a\u0430\u00bb:\u00a0<code>c.increment()<\/code>,\u00a0<code>c.x<\/code>.<\/p>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f\u00a0<code>x<\/code>:\u00a0<code>counter.x = 100<\/code>? \u042d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u00a0<code>counter<\/code>:<\/p>\n<pre><code class=\"scala\">counter.increment() \/\/ 1 counter.increment() \/\/ 2 \/\/ ... \u0437\u0434\u0435\u0441\u044c \u0435\u0449\u0435 \u043a\u043e\u0434 \/\/ counter.x = -10 \/\/ ... \u0437\u0434\u0435\u0441\u044c \u0435\u0449\u0435 \u043a\u043e\u0434 if (counter.x > 0) {   \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 counter.x \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e   \/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f counter.x   ... }<\/code><\/pre>\n<p>\u041d\u0443\u0436\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e <code>counter<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430:\u00a0<em>private<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u0415\u0441\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d, \u0442\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<em>public<\/em>\u00a0&#8212; \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437\u0432\u043d\u0435.<\/p>\n<pre><code class=\"scala\">class Counter {   private var x: Int = 0      def increment(): Unit = x = x + 1 }  val counter = new Counter counter.increment() counter.increment() println(counter.x)  \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:                     \/\/ variable x in class Counter cannot be accessed in Counter<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0435 <code>x<\/code> \u043d\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0438\u0437\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u043d\u0443\u0436\u0435\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437\u0432\u043d\u0435, \u043d\u043e \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u0431\u044b \u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Counter<\/code> \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\u00a0<code>x<\/code>.<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _ \/\/ \u0438\u043b\u0438 \u044f\u0432\u043d\u043e: var _x: Int = 0      def x: Int = _x         \/\/ \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f      def increment(): Unit = _x = _x + 1 }  val counter = new Counter counter.increment() counter.increment() println(counter.x)  \/\/ \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 counter.x = 0       \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f: value x_= is not a member of Counter counter._x = 0      \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:                     \/\/ variable _x in class Counter cannot be accessed in Counter<\/code><\/pre>\n<p>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<em>def<\/em>\u00a0\u043e\u0442 \u00abdefinition\u00bb. \u041f\u043e\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438\u00a0<em>val<\/em>\u00a0\u0438\u00a0<em>var<\/em>\u00a0\u043e\u0442 \u00abvalue\u00bb \u0438 \u00abvariable\u00bb \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e. \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u00ab_\u00bb, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u00ab=\u00bb \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438:<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _      def x: Int = _x      private var _step: Int = 1        \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435                                     \/\/ \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e step \u044d\u0442\u043e \u043f\u0430\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:   def step: Int = _step             \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f      def step_=(value: Int): Unit = {  \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438     _step = value   }      def increment(): Unit = _x = _x + step }<\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 Scala \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"scala\">class Counter {   private var _x: Int = _      def x: Int = _x      private var _step: Int = 1       \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0435 \u043f\u043e\u043b\u0435                                     \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f step \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442      def step_=(value: Int): Unit = { \/\/ \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438     _step = value   }      def increment(): Unit = _x = _x + _step }  val counter = new Counter counter.step = 10 \/\/ \u041e\u0428\u0418\u0411\u041a\u0410, \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f: value step is not a member of Counter<\/code><\/pre>\n<p><strong>\u0412\u043e\u043f\u0440\u043e\u0441<\/strong>: \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u0430\u043a\u00a0<code>var x: Int = _x<\/code>\u00a0\u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>Counter<\/code>?<\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e &#8212; \u043d\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<em>def<\/em>, \u043d\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b, \u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c.<\/p>\n<pre><code class=\"scala\">class Counter {   println(\"start main ctor\")      private var _x: Int = _      val x: Int = _x \/\/ \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442 x \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 _x \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b                   \/\/ \u043a \u043d\u0435\u043c\u0443 \u043d\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c      private var _step: Int = 1      def increment(): Unit = _x = _x + _step      println(\"end main ctor\") }  val counter = new Counter counter.increment() counter.increment() println(counter.x)<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code>defined class Counter start main ctor end main ctor counter: Counter = Counter@464b627c 0<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043c\u0435\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>Counter<\/code> \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432. \u0417\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043d\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<pre><code class=\"scala\">class Counter(private var _x: Int = 0) {  \/\/ \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c:                                           \/\/ Counter(Int)   def x: Int = _x      private var _step: Int = 1      def step: Int = _step      def step_=(value: Int): Unit = _step = value      def increment(): Unit = _x = _x + step }<\/code><\/pre>\n<p>\u0418\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 (\u00abauxilliary\u00bb) \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b:<\/p>\n<pre><code class=\"scala\">class Counter {  \/\/ \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:                  \/\/ Counter()   println(\"start main ctor\")      private var _x: Int = 0      def x: Int = _x      private var _step: Int = 1      def step: Int = _step      def step_=(value: Int): Unit = _step = value      def increment(): Unit = _x = _x + step      def this(initX: Int) = {  \/\/ \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: Counter(Int)     this()                  \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u0435\u0440\u0432\u044b\u043c     println(\"start aux ctor 1\")     _x = initX     println(\"end aux ctor 1\")   }      def this(initX: Int, initStep: Int) = {  \/\/ \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: Counter(Int, Int)     this(initX)                            \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430,                                            \/\/ \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440     println(\"start aux ctor 2\")     _step = initStep     println(\"end aux ctor 2\")   }      println(\"end main ctor\") }  val counter = new Counter(10, 2) counter.increment() println(counter.x)<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u044d\u0442\u043e\u0442:<\/p>\n<pre><code class=\"bash\">defined class Counter start main ctor end main ctor start aux ctor 1 end aux ctor 1 start aux ctor 2 end aux ctor 2 counter: Counter = Counter@64d9850 12<\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443 \u0438\u0437\u0432\u043d\u0435? \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430\u00a0<em>private<\/em>:<\/p>\n<pre><code class=\"scala\">class Counter private(private var x: Int = 0) {   \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 Counter }<\/code><\/pre>\n<p>\u0417\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<pre><code class=\"scala\">class Counter {   private def watchDog(): Unit = \/\/ ...      def increment(): Unit = {     watchDog()     \/\/ ...   } }<\/code><\/pre>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/h3>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u0432 Scala \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"scala\">object Empty { \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Empty   \/\/ \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430 }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430, \u0442\u043e \u043e\u043d\u043e \u043c\u0430\u043b\u043e \u0447\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043d\u043e \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u044b \u0441\u0432\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-349073","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349073","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=349073"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349073\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}