{"id":6954,"date":"2022-11-09T14:42:53","date_gmt":"2022-11-09T05:42:53","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6954"},"modified":"2022-11-09T15:12:57","modified_gmt":"2022-11-09T06:12:57","slug":"java-generic-enum","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6954","title":{"rendered":"Java Generic Enum"},"content":{"rendered":"<h1>Java Generic Enum<\/h1>\n<p>Java Enum \uc740 \ub0b4\ubd80\uc801\uc73c\ub85c Enum class \ub97c \uc774\ubbf8 \uc0c1\uc18d\ud558\uace0 \uc788\uae30 \ub54c\ubb38\uc5d0,<br \/>\n\ub2e4\ub978 \ud074\ub798\uc2a4\ub97c \uc0c1\uc18d\ud560 \uc218 \uc5c6\uc5b4, \uae30\ubcf8\uc801\uc73c\ub85c Generic \uc744 \uad6c\ud604\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud558\uc9c0\ub9cc, interface \ub97c \uc774\uc6a9\ud574 \uc720\uc0ac\ud55c \uae30\ub2a5\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>interface \uc0dd\uc131<\/h2>\n<p>getEnumConstants() \ub97c \uc774\uc6a9\ud574 \uac12\uc73c\ub85c\ubd80\ud130 Enum \uc744 \uc0dd\uc131\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-java\">public interface BaseEnum&lt;V&gt; {\n\n    V getValue();\n\n    static &lt;E extends Enum&lt;E&gt; &amp; BaseEnum&lt;ID&gt;, ID&gt; E fromValue(ID value, Class&lt;E&gt; type) {\n        if (value == null) {\n            return null;\n        }\n\n        for (E e : type.getEnumConstants()) {\n            if (e.getValue().equals(value)) {\n                return e;\n            }\n        }\n\n        return null;\n    }\n}<\/code><\/pre>\n<h2>Enum \uc0dd\uc131<\/h2>\n<p>String \uc73c\ub85c \uc800\uc7a5\ub418\ub294 Enum<\/p>\n<pre><code class=\"language-java\">public enum YNType implements BaseEnum&lt;String&gt; {\n\n    Y(&quot;Y&quot;),\n    N(&quot;N&quot;);\n\n    private final String value;\n\n    YNType(String value) {\n        this.value = value;\n    }\n\n    @Override\n    public String getValue() {\n        return value;\n    }\n\n    public static YNType fromValue(String value) {\n        return BaseEnum.fromValue(value, YNType.class);\n    }\n}<\/code><\/pre>\n<p>Integer \ub85c \uc800\uc7a5\ub418\ub294 Enum<\/p>\n<pre><code class=\"language-java\">public enum StatusType implements BaseEnum&lt;Integer&gt; {\n    BAD(1),\n    GOOD(2),\n    UNKNOWN(3);\n\n    private final Integer value;\n\n    StatusType(int value) {\n        this.value = value;\n    }\n\n    @Override\n    public Integer getValue() {\n        return value;\n    }\n\n    public static StatusType fromValue(Integer value) {\n        return BaseEnum.fromValue(value, StatusType.class);\n    }\n}<\/code><\/pre>\n<h2>\uc0ac\uc6a9\ubc95<\/h2>\n<pre><code class=\"language-java\">YNType ynType1 = YNType.Y;\nYNType ynType2 = YNType.fromValue(&quot;Y&quot;);\n\nStatusType statusType1 = StatusType.GOOD;\nStatusType statusType2 = StatusType.fromValue(1);\n\nSystem.out.println(ynType1);\nSystem.out.println(ynType2);\n\nSystem.out.println(statusType1);\nSystem.out.println(statusType2);\nSystem.out.println(statusType2.getValue());<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java Generic Enum Java Enum \uc740 \ub0b4\ubd80\uc801\uc73c\ub85c Enum class \ub97c \uc774\ubbf8 \uc0c1\uc18d\ud558\uace0 \uc788\uae30 \ub54c\ubb38\uc5d0, \ub2e4\ub978 \ud074\ub798\uc2a4\ub97c \uc0c1\uc18d\ud560 \uc218 \uc5c6\uc5b4, \uae30\ubcf8\uc801\uc73c\ub85c Generic \uc744 \uad6c\ud604\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4. \ud558\uc9c0\ub9cc, interface \ub97c \uc774\uc6a9\ud574 \uc720\uc0ac\ud55c \uae30\ub2a5\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. interface \uc0dd\uc131 getEnumConstants() \ub97c \uc774\uc6a9\ud574 \uac12\uc73c\ub85c\ubd80\ud130 Enum \uc744 \uc0dd\uc131\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. public interface BaseEnum&lt;V&gt; { V getValue(); static &lt;E extends Enum&lt;E&gt;\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6954\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-6954","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6954"}],"version-history":[{"count":3,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6954\/revisions"}],"predecessor-version":[{"id":6957,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6954\/revisions\/6957"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}