{"id":1812,"date":"2023-01-13T11:35:00","date_gmt":"2023-01-13T03:35:00","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=1812"},"modified":"2023-05-02T15:47:03","modified_gmt":"2023-05-02T07:47:03","slug":"%e3%80%90kotlin%e3%80%91enum-%e6%9e%9a%e8%88%89-%e7%af%84%e4%be%8b","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/%e3%80%90kotlin%e3%80%91enum-%e6%9e%9a%e8%88%89-%e7%af%84%e4%be%8b\/","title":{"rendered":"\u3010Kotlin\u3011Enum \u679a\u8209 \u7bc4\u4f8b"},"content":{"rendered":"<h1>\u3010Kotlin\u3011Enum \u679a\u8209 \u7bc4\u4f8b<\/h1>\n<h4>Kotlin \u4e2d\u7684 Enum \u6216\u7a31\u679a\u8209\uff0c\u662f\u7528\u4f86\u5b9a\u7fa9\u4e00\u7d44\u6709\u9650\u7684\u5e38\u6578\u7684\u8cc7\u6599\u985e\u578b\u3002\u6bcf\u500b Enum \u90fd\u6709\u4e00\u500b\u540d\u7a31\u548c\u4e00\u500b\u56fa\u5b9a\u7684\u503c\u3002 Enum \u5e38\u6578\u662f\u7269\u4ef6\uff0c\u4e26\u4e14\u90fd\u662f Enum \u985e\u578b\u7684\u5be6\u4f8b\u3002<\/h4>\n<h4>Enum \u662f\u4e00\u7a2e\u7279\u6b8a\u985e\u578b\uff0c\u53ef\u4ee5\u7528\u65bc\u5b9a\u7fa9\u4e00\u7d44\u6709\u9650\u7684\u5e38\u6578\uff0c\u4e26\u4e14\u53ef\u4ee5\u88ab\u7528\u65bc switch \u8a9e\u53e5\u3002 Enum \u53ef\u4ee5\u7528\u65bc\u5efa\u7acb\u81ea\u5df1\u7684\u985e\u578b\uff0c\u4e26\u4e14\u53ef\u4ee5\u5b9a\u7fa9\u81ea\u5df1\u7684\u65b9\u6cd5\u548c\u5c6c\u6027\u3002<\/h4>\n<hr \/>\n<h4>\u6587\u7ae0\u76ee\u9304<\/h4>\n<ol>\n<li><a href=\"#a\">Enum \u57fa\u672c<\/a><\/li>\n<li><a href=\"#b\">Enum \u5e36\u53c3\u6578<\/a><\/li>\n<li><a href=\"#c\">Enum \u8abf\u7528\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"#d\">Developer Documents Enum<\/a><\/li>\n<\/ol>\n<hr \/>\n<p><a id=\"a\"><\/a><\/p>\n<h4>1.Enum \u57fa\u672c<\/h4>\n<pre><code class=\"language-kotlin line-numbers\">enum class RegisterFragment {\n    JOIN_MEMBER,\n    USE_PURPOSE,\n}\n<\/code><\/pre>\n<p><a id=\"b\"><\/a><\/p>\n<h4>2.Enum \u5e36\u53c3\u6578<\/h4>\n<pre><code class=\"language-kotlin line-numbers\">enum class RegisterFragmentName(val page: String) {\n    JOIN_MEMBER(\"\u52a0\u5165\u6703\u54e1\"),\n    USE_PURPOSE(\"\u4f7f\u7528\u7528\u9014\");\n\n    fun hi() = \"hi ${this.page}\"\n}\n<\/code><\/pre>\n<p><a id=\"c\"><\/a><\/p>\n<h4>3.Enum \u8abf\u7528\u65b9\u6cd5<\/h4>\n<pre><code class=\"language-kotlin line-numbers\">\/\/\u8b80\u53d6\u540d\u7a31\nprintln(RegisterFragment.JOIN_MEMBER.name)\n\n\/\/\u8b80\u53d6\u7b2c\u5e7e\u4f4d\nprintln(RegisterFragment.JOIN_MEMBER.ordinal)\n\n\/\/\u53d6\u5f97\u9663\u5217\nprintln(enumValues&lt;RegisterFragment&gt;().size)\n\n\/\/\u5224\u65b7\nprintln(when(RegisterFragment.USE_PURPOSE) {\n    RegisterFragment.JOIN_MEMBER -&gt; \"\u52a0\u5165\u6703\u54e1\"\n    RegisterFragment.USE_PURPOSE -&gt; \"\u4f7f\u7528\u7528\u9014\"\n})\n\n\/\/\u53d6\u5f97\u53c3\u6578\nprintln(RegisterFragmentName.JOIN_MEMBER.page)\n\n\/\/\u8abf\u7528\u65b9\u6cd5\nprintln(RegisterFragmentName.USE_PURPOSE.hi())\n<\/code><\/pre>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2023\/01\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2023-01-13-113608.png\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2023\/01\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2023-01-13-113608.png\" alt=\"\" \/><\/a><\/p>\n<p><a id=\"d\"><\/a><\/p>\n<h4>4.Developer Documents Enum<\/h4>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.kotlincn.net\/docs\/reference\/enum-classes.html\" title=\"Open in Documents Enum\" target=\"_blank\" rel=\"noopener\">Open in Documents Enum<\/a><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u3010Kotlin\u3011Enum \u679a\u8209 \u7bc4\u4f8b Kotlin \u4e2d\u7684 Enum \u6216\u7a31\u679a\u8209\uff0c\u662f\u7528\u4f86\u5b9a\u7fa9\u4e00\u7d44\u6709\u9650\u7684\u5e38\u6578\u7684\u8cc7\u6599\u985e &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[6],"tags":[13,230,15],"class_list":["post-1812","post","type-post","status-publish","format-standard","hentry","category-kotlin","tag-android","tag-enum","tag-kotlin"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=1812"}],"version-history":[{"count":4,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1812\/revisions"}],"predecessor-version":[{"id":1913,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/1812\/revisions\/1913"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=1812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=1812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=1812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}