{"id":370424,"date":"2024-05-21T04:24:48","date_gmt":"2024-05-21T04:24:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=370424"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=370424","title":{"rendered":"<span>\u0418\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u044b \u0438 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\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<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/9i\/ir\/mo\/9iirmoje35mj4axwjupzdjc61o8.png\" width=\"400\" data-src=\"https:\/\/habrastorage.org\/webt\/9i\/ir\/mo\/9iirmoje35mj4axwjupzdjc61o8.png\"\/><\/figure>\n<blockquote>\n<p><em>\u0421\u0442\u0430\u0442\u044c\u044f, \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0441\u043a\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0438 \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u043c \u043b\u0435\u043a\u0446\u0438\u0438. \u0410 \u0435\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0430 Scala 2.<\/em><\/p>\n<p><a href=\"https:\/\/a-khakimov.github.io\/posts\/scala-implicits-and-typeclasses\" rel=\"noopener noreferrer nofollow\"><em>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/em><\/a><\/p>\n<\/blockquote>\n<h3>\u041f\u043b\u0430\u043d \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u043e\u0439<\/h3>\n<ul>\n<li>\n<p><a href=\"#implicit-conversions\" rel=\"noopener noreferrer nofollow\">Implicit conversions<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#implicit-parameters\" rel=\"noopener noreferrer nofollow\">Implicit parameters<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#implicit-classes\" rel=\"noopener noreferrer nofollow\">Implicit classes<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#type-classes\" rel=\"noopener noreferrer nofollow\">Type classes<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#simple-type-classes\" rel=\"noopener noreferrer nofollow\">Simple type classes<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>Implicit conversions<\/h3>\n<p>\u0418 \u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430! \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434. \u0412\u043e\u043f\u0440\u043e\u0441 &#8212; \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d?<\/p>\n<pre><code class=\"scala\">val x: String = 123 <\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435\u0442! \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u044c\u0435\u0442 \u043d\u0430\u0441 \u043f\u043e \u0440\u0443\u043a\u0430\u043c &#8212; \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f:<\/p>\n<pre><code>[error] ...: type mismatch; [error]  found   : Int(123) [error]  required: String [error]   val x: String = 123 [error]                   ^ [error] one error found [error] (Compile \/ compileIncremental) Compilation failed <\/code><\/pre>\n<p>\u041d\u043e \u0432 Scala \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"scala\">implicit def intToString(x: Int): String = x.toString  val x: String = 123 \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d intToString <\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f? \u0414\u0430! \u0427\u0442\u043e \u0436\u0435 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>implicit<\/code>, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e.<\/p>\n<pre><code class=\"scala\">implicit def func(param: A): B = ??? <\/code><\/pre>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043d\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f. \u041d\u043e \u0432\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 &#8212; \u043e\u043d\u0430 \u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e, \u0437\u0430\u0447\u0435\u043c \u0435\u0439 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435? \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0432\u0443\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u044f\u0432\u043d\u043e<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">implicit def intToString(x: Int): String = x.toString val x: String = intToString(123) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0442\u043e\u043c \u0438\u043b\u0438 \u0438\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">object my_implicits {     implicit def intToString(x: Int): String = x.toString } import my_implicits.intToString val x: String = 123 <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/p>\n<ul>\n<li>\n<p>\u041d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code><strong>implicit<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0435\u0439\u0442\u0430\/\u043a\u043b\u0430\u0441\u0441\u0430\/\u043e\u0431\u044a\u0435\u043a\u0442\u0430\/\u043c\u0435\u0442\u043e\u0434\u0430 (\u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435)<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043a\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <strong>\u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/strong><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">\/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \/\/ \u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e implicit def func(argA: A, argB: B): C = ??? <\/code><\/pre>\n<h4>Implicit scopes and priorities<\/h4>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c \u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/p>\n<h3>Local scope<\/h3>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0422\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"scala\">object Example {        implicit def intToString(x: Int): String = x.toString        val x: String = 123   } <\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e) \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"scala\">object Example {        implicit def intToString1(x: Int): String = x.toString     implicit def intToString2(x: Int): String = x.toString        val x: String = 123   }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \/\/ [error] Note that implicit conversions are not applicable because they are ambiguous: \/\/ [error]  both method intToString1 in object Example of type (x: Int): String \/\/ [error]  and method intToString2 in object Example of type (x: Int): String <\/code><\/pre>\n<h3>Imports<\/h3>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u043b\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"scala\">object ExternalImplicits {       implicit def intToString(x: Int): String = x.toString   }    object Example {        import ExternalImplicits.intToString     \/\/ \u0418\u041b\u0418 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435   import ExternalImplicits._        val x: String = 123   } <\/code><\/pre>\n<h3>\u041e\u0431\u044a\u0435\u043a\u0442\u044b-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u044b<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435 \u0442\u0438\u043f\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u043d\u0435\u044f\u0432\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Currency<\/code>, \u0442\u043e \u043d\u0435\u044f\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <code>Currency<\/code>.<\/p>\n<pre><code class=\"scala\">trait Currency   case class Dollar(amount: Double) extends Currency   case class Euro(amount: Double) extends Currency      object Currency {       implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount * 1.13)   }  object Example extends App {          val dollar: Dollar = Euro(100) \/\/ euroToDollar   } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 &#8212; \u043e\u0434\u043d\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0442\u043e \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"scala\">trait Currency   case class Dollar(amount: Double) extends Currency   case class Euro(amount: Double) extends Currency      object Currency {       implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount * 1.13) }  object Example extends App {        implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount)      val dollar: Dollar = Euro(100) \/\/ result: 100 } <\/code><\/pre>\n<h4>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435!<\/h4>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/hy\/fa\/n_\/hyfan_aw-0e2z7ihbml_-9shfzw.png\" width=\"350\" data-src=\"https:\/\/habrastorage.org\/webt\/hy\/fa\/n_\/hyfan_aw-0e2z7ihbml_-9shfzw.png\"\/><\/figure>\n<p>\u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0438\u043b\u043e\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c! \u041d\u0435\u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0442\u0440\u0443\u0434\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (\u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e). \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043a\u043e\u0434 \u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b!<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ce\/xz\/5c\/cexz5ccqtryihmyt6zme2g6ap70.png\" width=\"350\" data-src=\"https:\/\/habrastorage.org\/webt\/ce\/xz\/5c\/cexz5ccqtryihmyt6zme2g6ap70.png\"\/><\/figure>\n<p>\u0423 \u0432\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; \u0437\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437\u0443\u0447\u0430\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u043b\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c?<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 &#8212; \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u044f\u0437\u044b\u043a\u0430 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0442\u043e\u0438\u0442 \u0437\u043d\u0430\u0442\u044c \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0430\u043c\u0438 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u043d\u043e \u0435\u0449\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u0445 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<h3>Implicit parameters<\/h3>\n<pre><code class=\"scala\">def func(implicit x: Int): Unit = ??? <\/code><\/pre>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"scala\">def multiply(x: Int)(implicit y: Int) = x * y  implicit val z: Int = 10 \/\/ \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u043e\u0439  multiply(3) \/\/ result: 30  multiply(4) \/\/ result: 40 <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <code>multiply<\/code> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>y<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a <code>implicit<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0442\u0438\u043f\u043e\u043c, \u0442\u043e (\u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e) \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043e \u043a\u0430\u043a\u0443\u044e \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"scala\">implicit val z: Int = 10   implicit val y: Int = 42      multiply(3)  \/\/ [error]  ....scala:119:11: ambiguous implicit values: \/\/ [error]  both value z in object ExampleImplicitParameters of type Int \/\/ [error]  and value y in object ExampleImplicitParameters of type Int \/\/ [error]  match expected type Int \/\/ [error]   multiply(3) <\/code><\/pre>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441 \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><code>def func(implicit x: Int)<\/code> &#8212;  \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code><strong>x<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0439<\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int, y: Int)<\/code> &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code><strong>x<\/strong><\/code> \u0438 <code><strong>y<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><code>def func(x: Int, implicit y: Int)<\/code> &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<li>\n<p><code>def func(x: Int)(implicit y: Int)<\/code> &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code><strong>y<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0439<\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int)(y: Int)<\/code>  &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int)(implicit y: Int)<\/code> &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0433\u0440\u0443\u043f\u043f\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0433\u0435\u0440. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 id \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0432 \u043b\u043e\u0433\u0433\u0435\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u044f\u0432\u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u043f\u0438\u0441\u0430\u0442\u044c <code>logger.log(...)(requestContext)<\/code><\/p>\n<pre><code class=\"scala\">case class RequestContext(requestId: String)    class Logger {   def log(message: String)(ctx: RequestContext): Unit = {         println(s\"[${ctx.requestId}] $message\")     } }  object SomeApplication extends App {   val logger = new Logger()    def handle(requestContext: RequestContext) = {     logger.log(\"Starting process\")(requestContext)     \/\/ some action ...     logger.log(\"Continue process...\")(requestContext)     \/\/ some action ...     logger.log(\"End process\")(requestContext)   } } <\/code><\/pre>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"scala\">case class RequestContext(requestId: String)    class Logger {   def log(message: String)(implicit ctx: RequestContext): Unit = {         println(s\"[${ctx.requestId}] $message\")     } }  object SomeApplication extends App {   val logger = new Logger()    def handle(implicit requestContext: RequestContext) = {     logger.log(\"Starting process\")     \/\/ some action ...     logger.log(\"Continue process...\")     \/\/ some action ...     logger.log(\"End process\")   } } <\/code><\/pre>\n<h3>Implicit classes<\/h3>\n<p>\u0412 Scala \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438, \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"scala\">implicit class ImplicitClass(val field: Int) extends AnyVal {   def method: Unit = ??? } <\/code><\/pre>\n<h4>\u0417\u0430\u0447\u0435\u043c \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b?<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f! \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 &#8212; \u043a\u0430\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432? \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c, \u043d\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438, \u043a\u0430\u043a\u0438\u0435 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/xw\/xi\/vq\/xwxivqmmq_cb4pf70_jhveciede.png\" width=\"500\" data-src=\"https:\/\/habrastorage.org\/webt\/xw\/xi\/vq\/xwxivqmmq_cb4pf70_jhveciede.png\"\/><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432. \u0412 \u041e\u041e\u041f \u044f\u0437\u044b\u043a\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/adapter\" rel=\"noopener noreferrer nofollow\">\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/a>. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0442\u0438\u043f (\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441) <code>Int<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <code>IntAdapter<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<pre><code class=\"scala\">class IntAdapter(val i: Int) {   def isEven: Boolean = i % 2 == 0   def isOdd: Boolean = !isEven }  \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 new IntAdapter(42).isEven  \/\/ true new IntAdapter(42).isOdd   \/\/ false <\/code><\/pre>\n<p>\u0412 Scala \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"scala\">implicit class RichInt(val i: Int) extends AnyVal {   def isEven: Boolean = i % 2 == 0   def isOdd: Boolean = !isEven }  10.isEven  \/\/ true 10.isOdd   \/\/ false <\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u043e\u043d\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u0442\u0438\u043f\u0443 <code>Int<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<blockquote>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442 <\/em><code><em>AnyVal<\/em><\/code><em> \u0432 Scala \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <\/em><a href=\"https:\/\/docs.scala-lang.org\/overviews\/core\/value-classes.html\" rel=\"noopener noreferrer nofollow\"><em>value \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/em><\/a><em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432-\u043e\u0431\u0435\u0440\u0442\u043e\u043a.<\/em><\/p>\n<\/blockquote>\n<p>\u0412\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u043c, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043c\u0441\u044f \u043e\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0430\u0445\u0430\u0440\u0430 (\u0432 IntelliJ IDEA \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>Desugar Scala Code<\/code>), \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u043e\u0431\u0435\u0441\u0441\u0430\u0445\u0430\u0440\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u044f\u0432\u043d\u043e\u0435 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0438 \u0432\u044b\u0437\u043e\u0432 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<pre><code class=\"scala\">\/\/ \u041e\u0431\u0435\u0441\u0441\u0430\u0445\u0430\u0440\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 org.example.app.RichInt(10).isEven  \/\/ true org.example.app.RichInt(10).isOdd   \/\/ false <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/0t\/zx\/42\/0tzx42hdn_wptjpkdlftclyxfvm.png\" width=\"300\" data-src=\"https:\/\/habrastorage.org\/webt\/0t\/zx\/42\/0tzx42hdn_wptjpkdlftclyxfvm.png\"\/><\/figure>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u0440\u0438\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043e\u0432.<\/p>\n<h3>Type classes<\/h3>\n<p>\u0422\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 &#8212; \u044d\u0442\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/Polymorphism_(computer_science)#Ad_hoc_polymorphism\" rel=\"noopener noreferrer nofollow\">Ad-hoc \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430<\/a>, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u042d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<h4>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b <code>Circle<\/code> \u0438 <code>Rectangle<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043e\u0433\u0430\u0442\u0438\u0442\u044c \u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u0438.<\/p>\n<pre><code class=\"scala\">trait Area {   def area: Double }  class Circle(radius: Double) extends Area {   override def area: Double = math.Pi * math.pow(radius, 2) }  class Rectangle(width: Double, length: Double) extends Area {   override def area: Double = width * length }  \/\/ \u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f def areaOf(area: Area): Double = area.area  areaOf(new Circle(10)) areaOf(new Rectangle(5, 5)) <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Area<\/code> \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>area<\/code> \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u044b <code>Circle<\/code> \u0438 <code>Rectangle<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>areaOf<\/code>, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 <code>Area<\/code>.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u043f\u0440\u0438\u0441\u0443\u0449 \u041e\u041e\u041f, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043b\u0435\u0436\u0430\u0442 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u0422\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, <strong>\u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u044b \u0440\u044f\u0434\u043e\u043c<\/strong> \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0445 \u0437\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<h4>\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b<\/h4>\n<p>\u0422\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, <strong>\u043e\u0442\u0434\u0435\u043b\u0435\u043d\u044b<\/strong> \u043e\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0445 \u0437\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ob\/jl\/zj\/objlzj1ce1ujdbpzggjlwr_uw_c.png\" width=\"500\" data-src=\"https:\/\/habrastorage.org\/webt\/ob\/jl\/zj\/objlzj1ce1ujdbpzggjlwr_uw_c.png\"\/><\/figure>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Area<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u041e\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438 \u043c\u0435\u0442\u043e\u0434 \u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<pre><code class=\"scala\">\/\/ \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 case class Circle(radius: Double) case class Rectangle(width: Double, length: Double)  \/\/ \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 trait Area[A] {   def area(a: A): Double }  \/\/ \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e object CircleArea extends Area[Circle] {   override def area(circle: Circle): Double = math.Pi * math.pow(circle.radius, 2) }  object RectangleArea extends Area[Rectangle] {   override def area(rectangle: Rectangle): Double = rectangle.width * rectangle.length }  \/\/ \u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f def areaOf[A](shape: A, area: Area[A]): Double = area.area(shape)  areaOf(Circle(11), CircleArea) areaOf(Rectangle(12, 15), RectangleArea) <\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u0435\u0441\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 <code>Area<\/code> \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 <code>Circle<\/code> \u0438 <code>Rectangle<\/code>, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>areaOf<\/code> \u043d\u0435\u044f\u0432\u043d\u043e.<\/p>\n<pre><code class=\"scala\">implicit val circleArea: Area[Circle] = new Area[Circle] {   override def area(circle: Circle): Double = math.Pi * math.pow(circle.radius, 2) }  implicit val rectangleArea: Area[Rectangle] = new Area[Rectangle] {   override def area(rectangle: Rectangle): Double = rectangle.width * rectangle.length }  \/\/ \u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f def areaOf[A](figure: A)(implicit area: Area[A]): Double = area.area(figure)  areaOf(Circle(42)) areaOf(Rectangle(12, 15)) <\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0435\u0449\u0435 \u0434\u0430\u043b\u044c\u0448\u0435. \u041f\u0443\u0442\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>areaOf<\/code> \u043d\u0430 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <strong>\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/strong> \u0434\u043b\u044f \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>area<\/code> \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u043e\u043d \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0442\u0438\u043f\u0430\u043c <code>Circle<\/code> \u0438 <code>Rectangle<\/code>.<\/p>\n<pre><code class=\"scala\">\/\/ \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 implicit class AreaSyntax[A](val figure: A) extends AnyVal {   def area(implicit area: Area[A]): Double = area.area(figure) }  Circle(42).area Rectangle(12, 15).area <\/code><\/pre>\n<p>\u041f\u043e \u044d\u0442\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0432 \u041e\u041e\u041f \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u0432 Scala \u043e\u043d\u0438, \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043e\u0432, \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u044f\u0449\u043d\u043e \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<h4>\u0410\u043d\u0430\u0442\u043e\u043c\u0438\u044f \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h4>\n<p>\u0422\u0430\u043a \u0438\u0437 \u0447\u0435\u0433\u043e, \u0432 \u0438\u0442\u043e\u0433\u0435, \u0441\u0442\u0440\u043e\u044f\u0442\u0441\u044f \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b? \u041e\u043d\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0445 \u0442\u0440\u0435\u0445 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>trait (\u0441\u0430\u043c \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441)<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0442\u0440\u0435\u0439\u0442\u0430 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u043d\u0430 \u0431\u0430\u0437\u0435 implicit class (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u043e\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0440\u0435\u0439\u0442\u0430:<\/p>\n<pre><code class=\"scala\">trait TypeClass[A] {   def method(value: A): Unit } <\/code><\/pre>\n<p>\u042d\u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u0412\u0430\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0442\u0440\u0435\u0439\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0442\u0438\u043f\u043e\u043c <code>A<\/code>.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u044d\u0442\u043e\u0433\u043e \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 <code>Int<\/code>. \u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u0442\u0443\u0442 \u043f\u0438\u0448\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440, \u043f\u0440\u0438\u0447\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u043d\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u043e\u0439 <code>Instances<\/code>.<\/p>\n<pre><code class=\"scala\">object TypeClassInstances {   implicit val intInstance: TypeClass[Int] = new TypeClass[Int] {     def method(value: Int): Unit = ???   } } <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432 &#8212; \u044d\u0442\u043e \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"scala\">object TypeClassSyntax {   implicit class TypeClassOps[A](private val value: A) extends AnyVal {     def method(implicit ev: TypeClass[A]): Unit = ev.method(value)   } } <\/code><\/pre>\n<h4>\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h4>\n<p>\u0418\u043d\u0441\u0442\u0430\u043d\u0441 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (\u044f\u0432\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u043e).<\/p>\n<pre><code class=\"scala\">object SomeApp {   def someMethod[A](arg: A)(implicit t: TypeClass[A]): Unit = {     t.method(arg)   } } <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/docs.scala-lang.org\/scala3\/book\/ca-context-bounds.html\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0430\u0443\u043d\u0434\u044b<\/a> \u0442\u0430\u0439\u043f-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<pre><code class=\"scala\">object SomeApp {   def someMethod[A: TypeClass]: Unit = {     TypeClass[A].method   } } <\/code><\/pre>\n<p>\u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>apply<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<pre><code class=\"scala\">trait TypeClass[A] {   def method(value: A): Unit }  object TypeClass {   def apply[A](implicit ev: TypeClass[A]): TypeClass[A] = ev } <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044d\u0442\u043e\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"scala\">object SomeApp {   import TypeClassSyntax._      def someMethod[A: TypeClass](arg: A): Unit = {     arg.method   }   } <\/code><\/pre>\n<h3>Simple type classes<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0440\u0443 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438.<\/p>\n<h4>Show<\/h4>\n<p><code>Show<\/code> &#8212; \u044d\u0442\u043e \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u0434\u043b\u044f <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/Object.html#toString--\" rel=\"noopener noreferrer nofollow\">\u0434\u0436\u0430\u0432\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>toString<\/code><\/a>. \u041e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>show<\/code>.<\/p>\n<p>\u0412\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u044d\u0442\u043e\u0442 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e <code>toString<\/code> \u0443\u0436\u0435 \u0441\u043b\u0443\u0436\u0438\u0442 \u0442\u043e\u0439 \u0436\u0435 \u0446\u0435\u043b\u0438. \u041f\u0440\u0438\u0447\u0435\u043c \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>toString<\/code>. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>toString<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <code>Any<\/code> (\u0438\u043b\u0438 \u0434\u0436\u0430\u0432\u043e\u0432\u044b\u0439 <code>Object<\/code>) \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"scala\">(new {}).toString \/\/ result: \"example.ExampleApp$$anon$5@5b464ce8\" <\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 <code>Show<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0442\u0438\u043f\u043e\u0432. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"scala\">\/\/ \u0422\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 trait Show[A] {     def show(value: A): String   }      \/\/ \u041e\u0431\u044a\u0435\u043a\u0442-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d object Show {     def apply[A](implicit ev: Show[A]): Show[A] = ev   }      \/\/ \u0418\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f Int \u0438 String object ShowInstances {     implicit val showInt: Show[Int] = new Show[Int] {     def show(value: Int): String = value.toString   }    implicit val showString: Show[String] = new Show[String] {     def show(value: String): String = value   } }      \/\/ \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 object ShowSyntax {     implicit class ShowOps[A](private val value: A) extends AnyVal {       def show(implicit ev: Show[A]): Unit = ev.show(value)     }   }   <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>Show<\/code> c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<pre><code class=\"scala\">import ShowInstances._ import ShowSyntax._      val meaningOfLife = 42      Show[Int].show(meaningOfLife)   \/\/ result: \"42\"   \/\/ or meaningOfLife.show   \/\/ result: \"42\"   <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>Show<\/code> c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<pre><code class=\"scala\">import ShowInstances._ import ShowSyntax._    case class User(name: String, age: Int)  object User {      implicit val showUser: Show[User] = new Show[User] {     def show(user: User): String = s\"User(name = ${user.name}, age = ${user.age})\"   } }    val user = User(\"Mark\", 25) user.show \/\/ result: \"User(name = Mark, age = 25)\" <\/code><\/pre>\n<h4>Eq<\/h4>\n<p><code>Eq<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/Object.html#equals-java.lang.Object-\" rel=\"noopener noreferrer nofollow\">\u0434\u0436\u0430\u0432\u043e\u0432\u043e\u0433\u043e <code>equals<\/code><\/a>. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 Java <code>equals<\/code> \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0442\u0438\u043f\u0430 \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 (\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435), \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0432\u0435\u0441\u0435\u043b\u044b\u043c \u0431\u0430\u0433\u0430\u043c.<\/p>\n<pre><code class=\"scala\">\"Hello\" == 42 \/\/ res1: Boolean = false <\/code><\/pre>\n<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u044b \u043e\u0442\u0441\u0435\u0447\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code class=\"scala\">\/\/ \u0422\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441 trait Eq[A] {   def eqv(x: A, y: A): Boolean }  \/\/ \u041e\u0431\u044a\u0435\u043a\u0442-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d object Eq {   def apply[A](implicit ev: Eq[A]): Eq[A] = ev }    \/\/ \u0418\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f Int \u0438 String object EqInstances {   implicit val eqInt: Eq[Int] = new Eq[Int] {     def eqv(x: Int, y: Int): Boolean = x == y   }    implicit val eqString: Eq[String] = new Eq[String] {     def eqv(x: String, y: String): Boolean = x == y   } }  \/\/ \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 object EqSyntax {   implicit class EqOps[A](private val x: A) extends AnyVal {     def eqv(y: A)(implicit ev: Eq[A]): Boolean = ev.eqv(x, y)     def ===(y: A)(implicit ev: Eq[A]): Boolean = ev.eqv(x, y)     def =!=(y: A)(implicit ev: Eq[A]): Boolean = !ev.eqv(x, y)   } } <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>Eq<\/code> c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<pre><code class=\"scala\">import EqInstances._   import EqSyntax._    Eq[Int].eqv(2 + 2, 4)   \/\/ result: true      \"Hello\" === \"world\"     \/\/ result: false   \"Hello\" =!= \"world\"     \/\/ result: true   <\/code><\/pre>\n<p>\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0436\u0435\u0441\u0442\u043a\u043e \u043f\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c.<\/p>\n<pre><code class=\"scala\">\"Hello\" === 42   \/*     [error]  fff.scala:202:15: type mismatch;     [error]  found   : Int(42)     [error]  required: String     [error]   \"Hello\" === 42     [error]               ^     [error] one error found     [error] (Compile \/ compileIncremental) Compilation failed *\/ <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>Eq<\/code> c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<pre><code class=\"scala\">case class User(name: String, age: Int)      object User {   implicit val eqUser: Eq[User] = new Eq[User] {       def eqv(x: User, y: User): Boolean = x.name === y.name &amp;&amp; x.age === y.age   } }  val mark = User(\"Mark\", 25) val joe = User(\"Joe\", 33)  mark === joe  \/\/ result: false <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041e\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043e\u0432 \u0438 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u043d\u0430 \u043f\u0443\u0442\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f Scala \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u0430\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0441 \u0443\u043c\u043e\u043c. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u044b \u0438 \u0442\u0430\u0439\u043f\u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0433\u043e, \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438 \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u043e\u0449\u044c Scala.<\/p>\n<h3>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/typelevel.org\/cats\/typeclasses.html\" rel=\"noopener noreferrer nofollow\">https:\/\/typelevel.org\/cats\/typeclasses.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/medium.com\/@olxc\/type-classes-explained-a9767f64ed2c\" rel=\"noopener noreferrer nofollow\">https:\/\/medium.com\/@olxc\/type-classes-explained-a9767f64ed2c<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/typelevel.org\/cats\/typeclasses\/eq.html\" rel=\"noopener noreferrer nofollow\">https:\/\/typelevel.org\/cats\/typeclasses\/eq.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/typelevel.org\/cats\/typeclasses\/show.html\" rel=\"noopener noreferrer nofollow\">https:\/\/typelevel.org\/cats\/typeclasses\/show.html<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/799235\/\"> https:\/\/habr.com\/ru\/articles\/799235\/<\/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<figure class=\"\"><\/figure>\n<blockquote>\n<p><em>\u0421\u0442\u0430\u0442\u044c\u044f, \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0441\u043a\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0438 \u043f\u043e \u0441\u0443\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u043c \u043b\u0435\u043a\u0446\u0438\u0438. \u0410 \u0435\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0430 Scala 2.<\/em><\/p>\n<p><a href=\"https:\/\/a-khakimov.github.io\/posts\/scala-implicits-and-typeclasses\" rel=\"noopener noreferrer nofollow\"><em>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/em><\/a><\/p>\n<\/blockquote>\n<h3>\u041f\u043b\u0430\u043d \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u043e\u0439<\/h3>\n<ul>\n<li>\n<p><a href=\"#implicit-conversions\" rel=\"noopener noreferrer nofollow\">Implicit conversions<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#implicit-parameters\" rel=\"noopener noreferrer nofollow\">Implicit parameters<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#implicit-classes\" rel=\"noopener noreferrer nofollow\">Implicit classes<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#type-classes\" rel=\"noopener noreferrer nofollow\">Type classes<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#simple-type-classes\" rel=\"noopener noreferrer nofollow\">Simple type classes<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>Implicit conversions<\/h3>\n<p>\u0418 \u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430! \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434. \u0412\u043e\u043f\u0440\u043e\u0441 &#8212; \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d?<\/p>\n<pre><code class=\"scala\">val x: String = 123 <\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435\u0442! \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u044c\u0435\u0442 \u043d\u0430\u0441 \u043f\u043e \u0440\u0443\u043a\u0430\u043c &#8212; \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f:<\/p>\n<pre><code>[error] ...: type mismatch; [error]  found   : Int(123) [error]  required: String [error]   val x: String = 123 [error]                   ^ [error] one error found [error] (Compile \/ compileIncremental) Compilation failed <\/code><\/pre>\n<p>\u041d\u043e \u0432 Scala \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"scala\">implicit def intToString(x: Int): String = x.toString  val x: String = 123 \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d intToString <\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f? \u0414\u0430! \u0427\u0442\u043e \u0436\u0435 \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <code>implicit<\/code>, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e.<\/p>\n<pre><code class=\"scala\">implicit def func(param: A): B = ??? <\/code><\/pre>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043d\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f. \u041d\u043e \u0432\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 &#8212; \u043e\u043d\u0430 \u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e, \u0437\u0430\u0447\u0435\u043c \u0435\u0439 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435? \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0432\u0443\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u044f\u0432\u043d\u043e<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">implicit def intToString(x: Int): String = x.toString val x: String = intToString(123) <\/code><\/pre>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0442\u043e\u043c \u0438\u043b\u0438 \u0438\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">object my_implicits {     implicit def intToString(x: Int): String = x.toString } import my_implicits.intToString val x: String = 123 <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/p>\n<ul>\n<li>\n<p>\u041d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code><strong>implicit<\/strong><\/code><\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0440\u0435\u0439\u0442\u0430\/\u043a\u043b\u0430\u0441\u0441\u0430\/\u043e\u0431\u044a\u0435\u043a\u0442\u0430\/\u043c\u0435\u0442\u043e\u0434\u0430 (\u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435)<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043a\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <strong>\u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<\/strong><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"scala\">\/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u0432\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \/\/ \u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e implicit def func(argA: A, argB: B): C = ??? <\/code><\/pre>\n<h4>Implicit scopes and priorities<\/h4>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c \u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/p>\n<h3>Local scope<\/h3>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0422\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"scala\">object Example {        implicit def intToString(x: Int): String = x.toString        val x: String = 123   } <\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430\u043c\u0438, \u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e) \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"scala\">object Example {        implicit def intToString1(x: Int): String = x.toString     implicit def intToString2(x: Int): String = x.toString        val x: String = 123   }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \/\/ [error] Note that implicit conversions are not applicable because they are ambiguous: \/\/ [error]  both method intToString1 in object Example of type (x: Int): String \/\/ [error]  and method intToString2 in object Example of type (x: Int): String <\/code><\/pre>\n<h3>Imports<\/h3>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u043b\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"scala\">object ExternalImplicits {       implicit def intToString(x: Int): String = x.toString   }    object Example {        import ExternalImplicits.intToString     \/\/ \u0418\u041b\u0418 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435   import ExternalImplicits._        val x: String = 123   } <\/code><\/pre>\n<h3>\u041e\u0431\u044a\u0435\u043a\u0442\u044b-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u044b<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435 \u0442\u0438\u043f\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u043d\u0435\u044f\u0432\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Currency<\/code>, \u0442\u043e \u043d\u0435\u044f\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <code>Currency<\/code>.<\/p>\n<pre><code class=\"scala\">trait Currency   case class Dollar(amount: Double) extends Currency   case class Euro(amount: Double) extends Currency      object Currency {       implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount * 1.13)   }  object Example extends App {          val dollar: Dollar = Euro(100) \/\/ euroToDollar   } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0439 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 &#8212; \u043e\u0434\u043d\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d\u0435, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0442\u043e \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"scala\">trait Currency   case class Dollar(amount: Double) extends Currency   case class Euro(amount: Double) extends Currency      object Currency {       implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount * 1.13) }  object Example extends App {        implicit def euroToDollar(euro: Euro): Dollar = Dollar(euro.amount)      val dollar: Dollar = Euro(100) \/\/ result: 100 } <\/code><\/pre>\n<h4>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0435\u0440\u0435\u0436\u0435\u043d\u0438\u0435!<\/h4>\n<figure class=\"\"><\/figure>\n<p>\u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0438\u043b\u043e\u0439 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c! \u041d\u0435\u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0442\u0440\u0443\u0434\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 (\u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e). \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043a\u043e\u0434 \u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u044b!<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0423 \u0432\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; \u0437\u0430\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437\u0443\u0447\u0430\u043b\u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u043b\u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0442\u0438\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c?<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 &#8212; \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u044f\u0437\u044b\u043a\u0430 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0442\u043e\u0438\u0442 \u0437\u043d\u0430\u0442\u044c \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0430\u043c\u0438 \u0438\u043c\u043f\u043b\u0438\u0441\u0438\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u043d\u043e \u0435\u0449\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u0445 \u044f\u0437\u044b\u043a\u0430.<\/p>\n<h3>Implicit parameters<\/h3>\n<pre><code class=\"scala\">def func(implicit x: Int): Unit = ??? <\/code><\/pre>\n<p>\u041d\u0435\u044f\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0437 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"scala\">def multiply(x: Int)(implicit y: Int) = x * y  implicit val z: Int = 10 \/\/ \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0435\u044f\u0432\u043d\u043e\u0439  multiply(3) \/\/ result: 30  multiply(4) \/\/ result: 40 <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443 \u043c\u0435\u0442\u043e\u0434\u0430 <code>multiply<\/code> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>y<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u043e. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u0430 \u043a\u0430\u043a <code>implicit<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0432\u0435 \u043d\u0435\u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0442\u0438\u043f\u043e\u043c, \u0442\u043e (\u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e) \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043e \u043a\u0430\u043a\u0443\u044e \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"scala\">implicit val z: Int = 10   implicit val y: Int = 42      multiply(3)  \/\/ [error]  ....scala:119:11: ambiguous implicit values: \/\/ [error]  both value z in object ExampleImplicitParameters of type Int \/\/ [error]  and value y in object ExampleImplicitParameters of type Int \/\/ [error]  match expected type Int \/\/ [error]   multiply(3) <\/code><\/pre>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441 \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p><code>def func(implicit x: Int)<\/code> &#8212;  \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code><strong>x<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0439<\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int, y: Int)<\/code> &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code><strong>x<\/strong><\/code> \u0438 <code><strong>y<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p><code>def func(x: Int, implicit y: Int)<\/code> &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<li>\n<p><code>def func(x: Int)(implicit y: Int)<\/code> &#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code><strong>y<\/strong><\/code> \u043d\u0435\u044f\u0432\u043d\u044b\u0439<\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int)(y: Int)<\/code>  &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<li>\n<p><code>def func(implicit x: Int)(implicit y: Int)<\/code> &#8212; <strong>\u043e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0433\u0440\u0443\u043f\u043f\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0439 \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0433\u0435\u0440. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 id \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0432 \u043b\u043e\u0433\u0433\u0435\u0440 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u044f\u0432\u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u043f\u0438\u0441\u0430\u0442\u044c <code>logger.log(...)(requestContext)<\/code><\/p>\n<pre><code class=\"scala\">case class RequestContext(requestId: String)    class Logger {   def log(message: String)(ctx: RequestContext): Unit = {         println(s\"[${ctx.requestId}] $message\")     } }  object SomeApplication extends App {   val logger = new Logger()    def handle(requestContext: RequestContext) = {     logger.log(\"Starting process\")(requestContext)     \/\/ some action ...     logger.log(\"Continue process...\")(requestContext)     \/\/ some action ...     logger.log(\"End process\")(requestContext)   } } <\/code><\/pre>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044f\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"scala\">case class RequestContext(requestId: String)    class Logger {   def log(message: String)(implicit ctx: RequestContext): Unit = {         println(s\"[${ctx.requestId}] $message\")     } }  object SomeApplication extends App {   val logger = new Logger()    def handle(implicit requestContext: RequestContext) = {     logger.log(\"Starting process\")     \/\/ some action ...     logger.log(\"Continue process...\")     \/\/ some action ...     logger.log(\"End process\")   } } <\/code><\/pre>\n<h3>Implicit classes<\/h3>\n<p>\u0412 Scala \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0435\u044f\u0432\u043d\u044b\u043c\u0438, \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"scala\">implicit class ImplicitClass(val field: Int) extends AnyVal {   def method: Unit = ??? } <\/code><\/pre>\n<h4>\u0417\u0430\u0447\u0435\u043c \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b?<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f! \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 &#8212; \u043a\u0430\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432? \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c, \u043d\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438, \u043a\u0430\u043a\u0438\u0435 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c.<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432. \u0412 \u041e\u041e\u041f \u044f\u0437\u044b\u043a\u0430\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c <a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/adapter\" rel=\"noopener noreferrer nofollow\">\u0430\u0434\u0430\u043f\u0442\u0435\u0440<\/a>. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0442\u0438\u043f (\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441) <code>Int<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 <code>IntAdapter<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<pre><code class=\"scala\">class IntAdapter(val i: Int) {   def isEven: Boolean = i % 2 == 0   def isOdd: Boolean = !isEven }  \/\/<\/code><\/pre>\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-370424","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370424","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=370424"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/370424\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}