优化枚举类

This commit is contained in:
zhaoyong 2021-12-13 18:47:59 +08:00
parent 8bb2fa71f3
commit c531135190
2 changed files with 9 additions and 1 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.axzo.framework</groupId>
<artifactId>common-common</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,5 +1,7 @@
package cn.azxo.framework.common.model;
import java.util.stream.Stream;
/**
* 枚举抽象类
*
@ -21,4 +23,10 @@ public interface EnumBase<T> {
*/
String getMessage();
static <T extends EnumBase> T getByCode(Class<T> clazz, Object code) {
return Stream.of(clazz.getEnumConstants())
.filter(v -> v.getCode().equals(code))
.findAny().orElse(null);
}
}