{"id":2088,"date":"2018-05-03T10:20:05","date_gmt":"2018-05-03T01:20:05","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2088"},"modified":"2023-05-27T20:39:54","modified_gmt":"2023-05-27T11:39:54","slug":"%e3%80%90java%e3%80%91%e5%88%97%e6%8c%99%e5%9e%8b%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2088","title":{"rendered":"\u3010Java\u3011\u5217\u6319\u578b(enum)\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u5217\u6319\u578b\u306e\u7279\u5fb4<\/h2>\n<ul>\n<li>\u30af\u30e9\u30b9\u306e\u5185\u90e8\u306b\u5b9a\u7fa9\u3057\u305f\u5834\u5408\u306f\u3001\u81ea\u52d5\u7684\u306bstatic\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<li>\u5217\u6319\u578b\u5185\u90e8\u3067\u3001\u72ec\u81ea\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3001\u30e1\u30bd\u30c3\u30c9\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>\u5217\u6319\u578b\u306e\u610f\u7fa9<\/h2>\n<h3>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u78ba\u5b9f\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/h3>\n<p>\u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570\u3084\u623b\u308a\u5024\u306benum\u3092\u4f7f\u3046\u3053\u3068\u3067\u305d\u308c\u4ee5\u5916\u306e\u5024\u306f\u53d6\u3089\u306a\u3044\u3068\u3044\u3046\u5f62\u3067\u7e1b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4fdd\u5b88\u6027\u3084\u78ba\u5b9f\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u4f8b\u3048\u3070\u3001\u4ed6\u306e\u578b\u3067\u3042\u308c\u3070\u4e0d\u6b63\u306a\u5024\u304c\u5165\u308a\u3048\u308b\u3002<\/h3>\n<p>static final\u3067\u3082\u540c\u3058\u3088\u3046\u306b\u4e0d\u6b63\u306a\u5024\u306f\u5165\u3089\u306a\u3044\u306e\u3067\u3059\u304c\u3001enum\u3067\u3042\u308c\u3070\u5024\u306e\u7a2e\u985e\u3059\u3089\u7e1b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3088\u308a\u5f37\u529b\u306a\u56fa\u5b9a\u5024\u306b\u306a\u308b\u3068\u8a00\u3048\u307e\u3059\u3002<\/p>\n<h4>String\u578b<\/h4>\n<p>\u6587\u5b57\u5217\u3092\u671f\u5f85\u3057\u305f\u3044\u306e\u306b\u3001<span style=\"color: #ff0000;\"><strong>null\u3084\u3001\u7a7a\u767d\u7b49\u306e\u4e0d\u6b63\u306a\u5024\u304c\u5165\u308a\u3048\u308b\u3002<\/strong><\/span><\/p>\n<h4>int\u578b<\/h4>\n<p>\u6574\u6570\u5024\u3092\u5165\u308c\u305f\u3044\u306e\u306b\u3001<span style=\"color: #ff0000;\"><strong>-99\u7b49\u306e\u4e0d\u6b63\u306a\u5024\u304c\u5165\u308a\u3048\u308b\u3002<\/strong><\/span><\/p>\n<h4>boolean\u578b<\/h4>\n<p>true\u3001false\u306e2\u7a2e\u985e\u306e\u5024\u3057\u304b\u5165\u308a\u3048\u306a\u3044\u304c\u3001<span style=\"color: #ff0000;\"><strong>3\u7a2e\u985e\u4ee5\u4e0a\u306e\u5024\u306f\u6271\u3048\u306a\u3044\u3002<\/strong><\/span><\/p>\n<h3>\u5217\u6319\u578b\u306a\u3089\u3001\u300c\u6307\u5b9a\u3057\u305f\u5024\u300d\u306e\u307f\u5024\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u53ef\u80fd<\/h3>\n<h4>\u69cb\u6587<\/h4>\n<pre class=\"lang:default decode:true\">\u30a2\u30af\u30bb\u30b9\u4fee\u98fe\u5b50 enum \u5217\u6319\u578b\u540d{\r\n  \u5217\u6319\u5b501,\u5217\u6319\u5b502,\u5217\u6319\u5b503;\r\n}<\/pre>\n<h4>\u30b5\u30f3\u30d7\u30eb<\/h4>\n<p>Java\u306e\u6a19\u6e96\u898f\u7d04\u3067\u306f\u3001\u5217\u6319\u578b\u306b\u306f<span style=\"color: #ff0000;\"><strong>\u5927\u6587\u5b57\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<pre class=\"lang:default decode:true\">public enum yasai{\r\n\tNINJIN,GOBOU,KYUURI;\r\n}\r\n\r\npublic static void main(String[] args) {\r\n\tSystem.out.println(yasai.NINJIN);\r\n}<\/pre>\n<h4>\u5b9f\u884c\u7d50\u679c<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2098\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/05\/NINJA.png\" alt=\"\" width=\"276\" height=\"96\" \/><\/p>\n<h2>Enum\u306f\u3001\u30af\u30e9\u30b9\u3068\u3057\u3066\u5ba3\u8a00\u53ef\u80fd<\/h2>\n<p>enum\u306f\u3001\u4e00\u3064\u306e\u30af\u30e9\u30b9\u3067\u3082\u3042\u308b\u306e\u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u4e00\u3064\u306e\u30af\u30e9\u30b9\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u3082\u5ba3\u8a00\u304c\u53ef\u80fd\u3067\u3059\u3002C\u8a00\u8a9e\u306b\u3082\u5217\u6319\u578b\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u30af\u30e9\u30b9\u6a5f\u80fd\u306fC\u8a00\u8a9e\u306b\u306f\u306a\u3044\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p><strong>Yasai.java<\/strong><\/p>\n<pre class=\"lang:default decode:true\">package test3;\r\n\r\npublic enum Yasai{\r\n\tNINJIN,GOBOU,KYUURI;\r\n\r\n    \/\/ \u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5b9a\u7fa9\r\n    private int id;\r\n    \r\n    \/\/ \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5b9a\u7fa9\r\n    private Yasai(int id) {\r\n        this.id = id;\r\n    }\r\n}<\/pre>\n<p>\u30af\u30e9\u30b9\u306a\u306e\u3067\u5217\u6319\u3059\u308b\u5024\u3068\u306f\u5225\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u3084\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306a\u3069\u3082\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305fenum\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u30a2\u30af\u30bb\u30b9\u4fee\u98fe\u5b50\u3068\u3057\u3066private\u306e\u307f\u3092\u53d6\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u5225\u306e\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u4f5c\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u304c\u3001\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5217\u6319\u578b\u306e\u7279\u5fb4 \u30af\u30e9\u30b9\u306e\u5185\u90e8\u306b\u5b9a\u7fa9\u3057\u305f\u5834\u5408\u306f\u3001\u81ea\u52d5\u7684\u306bstatic\u306b\u306a\u308a\u307e\u3059\u3002 \u5217\u6319\u578b\u5185\u90e8\u3067\u3001\u72ec\u81ea\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3001\u30e1\u30bd\u30c3\u30c9\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u5217\u6319\u578b\u306e\u610f\u7fa9 \u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u78ba\u5b9f\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002 \u30e1 [&hellip;]","protected":false},"author":1,"featured_media":2128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2088"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2088"}],"version-history":[{"count":17,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2088\/revisions"}],"predecessor-version":[{"id":20243,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2088\/revisions\/20243"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2128"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2088"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}