{"id":22840,"date":"2020-12-17T09:00:34","date_gmt":"2020-12-17T00:00:34","guid":{"rendered":"https:\/\/mole-kingdom.com\/wpbl\/?p=22840"},"modified":"2020-12-13T09:19:53","modified_gmt":"2020-12-13T00:19:53","slug":"%e3%82%b7%e3%83%bc%e3%83%ab%e3%82%af%e3%83%a9%e3%82%b9%e5%af%86%e9%96%89%e3%82%af%e3%83%a9%e3%82%b9-kotlin","status":"publish","type":"post","link":"https:\/\/mole-kingdom.com\/wpbl\/2020\/12\/17\/22840.html","title":{"rendered":"\u30b7\u30fc\u30eb\u30af\u30e9\u30b9(\u5bc6\u9589\u30af\u30e9\u30b9) : kotlin"},"content":{"rendered":"<p class=\"outline02\">\n<p><a href=\"https:\/\/kotlinlang.org\/docs\/reference\/sealed-classes.html\" rel=\"noopener\" target=\"_blank\">\u30b7\u30fc\u30eb\u30af\u30e9\u30b9(\u5bc6\u9589\u30af\u30e9\u30b9)<\/a><\/p>\n<p><\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306f\u9650\u5b9a\u7684\u306a\u30af\u30e9\u30b9\u968e\u5c64\u3092\u8868\u3059\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3053\u306e\u30af\u30e9\u30b9\u3067\u306f\u5024\u306f\u9650\u5b9a\u3055\u308c\u305f\u30bb\u30c3\u30c8\u306e\u578b\u306e1\u3064\u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u308c\u4ee5\u5916\u306e\u578b\u3092\u6301\u3064\u3053\u3068\u304c\u51fa\u6765\u307e\u305b\u3093\u3002 <\/p>\n<p>\u3042\u308b\u610f\u5473\u3067\u3001\u3053\u308c\u3089\u306f\u5217\u6319\u578b\u30af\u30e9\u30b9\u306e\u62e1\u5f35\u3067\u3059\u3002:<br \/>\n\u5217\u6319\u578b\u306e\u5024\u306e\u30bb\u30c3\u30c8\u3082\u5236\u9650\u3055\u308c\u307e\u3059\u304c\u3001\u5404\u5217\u6319\u578b\u5b9a\u6570\u306f\u5358\u4e00\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3068\u3057\u3066\u306e\u307f\u5b58\u5728\u3059\u308b\u306e\u306b\u5bfe\u3057\u3001\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u306f\u3001\u72b6\u614b\u3092\u542b\u3080\u3053\u3068\u304c\u3067\u304d\u308b\u8907\u6570\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6301\u3066\u307e\u3059\u3002<\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u3092\u5ba3\u8a00\u3059\u308b\u306b\u306f\u3001\u30af\u30e9\u30b9\u540d\u306e\u524d\u306bsealed\u4fee\u98fe\u5b50\u3092\u52a0\u3048\u307e\u3059\u3002\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306f\u30b5\u30d6\u30af\u30e9\u30b9\u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u308c\u3089\u306f\u3059\u3079\u3066\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u81ea\u4f53\u3068\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u3067\u5ba3\u8a00\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \uff08Kotlin 1.1\u3088\u308a\u524d\u306f\u3001\u30eb\u30fc\u30eb\u306f\u3055\u3089\u306b\u53b3\u683c\u3067\u3057\u305f\u3002\u30af\u30e9\u30b9\u306f\u3001\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306e\u5ba3\u8a00\u5185\u306b\u30cd\u30b9\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\uff09\u3002<\/p>\n<pre class=\"brush: kotlin; title: ; notranslate\" title=\"\">\r\nsealed class Expr\r\ndata class Const(val number: Double) : Expr()\r\ndata class Sum(val e1: Expr, val e2: Expr) : Expr()\r\nobject NotANumber : Expr()\r\n<\/pre>\n<p>(\u4e0a\u8a18\u306e\u4f8b\u3067\u306f\u3001Kotlin 1.1\u3067\u8ffd\u52a0\u3055\u308c\u305f\u65b0\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30c7\u30fc\u30bf\u30af\u30e9\u30b9\u304c\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u3092\u542b\u3080\u4ed6\u306e\u30af\u30e9\u30b9\u3092\u7d99\u627f\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002)<\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u81ea\u4f53\u306f\u62bd\u8c61\u30af\u30e9\u30b9\u3067\u3042\u308a\u3001\u76f4\u63a5\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u306f\u51fa\u6765\u305a\u3001\u62bd\u8c61\u30e1\u30f3\u30d0\u3092\u6301\u3066\u307e\u305b\u3093\u3002<\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306f\u3001private\u3067\u306f\u306a\u3044\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u6301\u3064\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\uff08\u305d\u308c\u3089\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067private\u3067\u3059\uff09\u3002<\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3059\u308b\u30af\u30e9\u30b9\uff08\u9593\u63a5\u7d99\u627f\uff09\u306f\u3001\u5fc5\u305a\u3057\u3082\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u306f\u306a\u304f\u3001\u3069\u3053\u306b\u3067\u3082\u914d\u7f6e\u3067\u304d\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308b\u4e3b\u306a\u5229\u70b9\u306f\u3001when\u5f0f\u3067\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u304c\u3059\u3079\u3066\u306e\u30b1\u30fc\u30b9\u3092\u30ab\u30d0\u30fc\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u308b\u5834\u5408\u306f\u3001\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306belse\u53e5\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305f\u3060\u3057\u3001\u3053\u308c\u306fwhen\u3092\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068\u3057\u3066\u3067\u306f\u306a\u304f\u3001\u5f0f\u3068\u3057\u3066\u4f7f\u7528\uff08\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u4f7f\u7528\uff09\u3059\u308b\u5834\u5408\u306b\u306e\u307f\u6a5f\u80fd\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: kotlin; title: ; notranslate\" title=\"\">\r\nfun eval(expr: Expr): Double = when(expr) {\r\n    is Const -&gt; expr.number\r\n    is Sum -&gt; eval(expr.e1) + eval(expr.e2)\r\n    NotANumber -&gt; Double.NaN\r\n    \/\/ \u5168\u3066\u306e\u30b1\u30fc\u30b9\u3092\u30ab\u30d0\u30fc\u3057\u3066\u3044\u308b\u70ba\u3001`else`\u53e5\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30b7\u30fc\u30eb\u30af\u30e9\u30b9(\u5bc6\u9589\u30af\u30e9\u30b9) \u30b7\u30fc\u30eb\u30af\u30e9\u30b9\u306f\u9650\u5b9a\u7684\u306a\u30af\u30e9\u30b9\u968e\u5c64\u3092\u8868\u3059\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002 \u3053\u306e\u30af\u30e9\u30b9\u3067\u306f\u5024\u306f\u9650\u5b9a\u3055\u308c\u305f\u30bb\u30c3\u30c8\u306e\u578b\u306e1\u3064\u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u305d\u308c\u4ee5\u5916\u306e\u578b\u3092\u6301\u3064\u3053\u3068\u304c\u51fa\u6765\u307e\u305b\u3093\u3002 \u3042\u308b\u610f\u5473\u3067\u3001\u3053\u308c\u3089\u306f\u5217\u6319\u578b...  <a class=\"excerpt-read-more\" href=\"https:\/\/mole-kingdom.com\/wpbl\/2020\/12\/17\/22840.html\" title=\"Read \u30b7\u30fc\u30eb\u30af\u30e9\u30b9(\u5bc6\u9589\u30af\u30e9\u30b9) : kotlin\">\u3082\u3063\u3068\u8aad\u3080 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[124],"tags":[],"class_list":["post-22840","post","type-post","status-publish","format-standard","hentry","category-kotlin"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2pLuj-5Wo","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":22847,"url":"https:\/\/mole-kingdom.com\/wpbl\/2020\/12\/21\/22847.html","url_meta":{"origin":22840,"position":0},"title":"\u30a8\u30af\u30b9\u30c6\u30f3\u30b7\u30e7\u30f3(\u62e1\u5f35) : kotlin","author":"moleking","date":"2020\u5e7412\u670821\u65e5","format":false,"excerpt":"\u203b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u5168\u3066\"Target platform: JVMRunning on kotlin v\u2026","rel":"","context":"kotlin","block_context":{"text":"kotlin","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/programming\/kotlin"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24858,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/23\/24858.html","url_meta":{"origin":22840,"position":1},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(\u7d42)","author":"moleking","date":"2021\u5e746\u670823\u65e5","format":false,"excerpt":"\u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u9593\u306e\u5171\u6709 ViewModel 4. \u5171\u6709 ViewModel \u3092\u4f5c\u6210\u3059\u308b OrderVi\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24848,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/17\/24848.html","url_meta":{"origin":22840,"position":2},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(2)","author":"moleking","date":"2021\u5e746\u670817\u65e5","format":false,"excerpt":"Layouts Kotlin\u306e\u30af\u30e9\u30b9\u3068\u7d99\u627f 2. \u30af\u30e9\u30b9\u968e\u5c64\u3068\u306f \u4e00\u5fdc\u3001\"\u8c46\u985e\"\u306e\u3068\u3053\u308d\u306e\u30ea\u30f3\u30af\u304ch\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":22838,"url":"https:\/\/mole-kingdom.com\/wpbl\/2020\/12\/15\/22838.html","url_meta":{"origin":22840,"position":3},"title":"\u578b\u5224\u5b9a\u3068\u30ad\u30e3\u30b9\u30c8 : kotlin","author":"moleking","date":"2020\u5e7412\u670815\u65e5","format":false,"excerpt":"\u578b\u5224\u5b9a\u3068\u30ad\u30e3\u30b9\u30c8 is\u6f14\u7b97\u5b50\u3068!\u6f14\u7b97\u5b50\u306b\u3088\u308b\u578b\u5224\u5b9a \u203b\u3053\u308cis\u6f14\u7b97\u5b50\u3068\u5426\u5b9a\u306e!\u6f14\u7b97\u5b50\u306e\u7d44\u307f\u5408\u308f\u305b\u3060\u304b\u2026","rel":"","context":"kotlin","block_context":{"text":"kotlin","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/programming\/kotlin"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24853,"url":"https:\/\/mole-kingdom.com\/wpbl\/2021\/06\/20\/24853.html","url_meta":{"origin":22840,"position":4},"title":"\u300eWelcome to Android Basics in Kotlin\u300f\u3092\u3084\u3063\u305f(3)","author":"moleking","date":"2021\u5e746\u670820\u65e5","format":false,"excerpt":"\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3 \u753b\u9762\u9593\u3092\u79fb\u52d5\u3059\u308b 2. \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u8a73\u7d30 \u30bb\u30c3\u30c8\u306e\u8a73\u7d30 All of the co\u2026","rel":"","context":"Android","block_context":{"text":"Android","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/os\/android"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":19032,"url":"https:\/\/mole-kingdom.com\/wpbl\/2018\/05\/01\/19032.html","url_meta":{"origin":22840,"position":5},"title":"\u3046\u306b\u306e\u30c8\u30b2\u306f\u523a\u3055\u308b\u3068\u75db\u3044(\u00b4\uff65\u03c9\uff65\uff40)-11","author":"moleking","date":"2018\u5e745\u67081\u65e5","format":false,"excerpt":"\u672c\u683c\u7684\u306b\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3092\u8a66\u307f\u308b(\uff40\u30fb\u03c9\u30fb\u00b4) \u51c4\u304f\u30d9\u30bf\u306a\u66f8\u304d\u65b9\u3092\u3057\u3066\u304d\u305f\u306e\u3067\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3092\u3059\u308b\u2026","rel":"","context":"C#","block_context":{"text":"C#","link":"https:\/\/mole-kingdom.com\/wpbl\/category\/programming\/csharp"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/22840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/comments?post=22840"}],"version-history":[{"count":1,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/22840\/revisions"}],"predecessor-version":[{"id":22841,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/posts\/22840\/revisions\/22841"}],"wp:attachment":[{"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/media?parent=22840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/categories?post=22840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mole-kingdom.com\/wpbl\/wp-json\/wp\/v2\/tags?post=22840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}