> For the complete documentation index, see [llms.txt](https://book.rizon.top/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.rizon.top/xue-xi-bi-ji/java_code_snippets.md).

# java code snippets

枚举的巧妙用法

```java
public enum Env {

        INNER("inner") {
            @Override
            public String env() {
                return "";
            }
        },

        COMMON("common") {
            @Override
            public String env() {
                return "";
            }
        },

        TEST("test") {
            @Override
            public String env() {
                return "_test";
            }
        };

        public final String env;

        Env(String evn) {
            this.env = evn;
        }

        public abstract String env();

        public static Env of(final String evn) {
            Env[] envs = Env.values();
            for (Env env : envs) {
                if (env.env.equalsIgnoreCase(evn)) {
                    return env;
                }
            }
            throw new BossBizException("不合法的env:" + Objects.toString(evn));
        }
    }
```
