泛型t约束继承

 <T extends BaseEnum>
 public static <T extends BaseEnum> T valueOfCode(Class<T> clazz, Integer code) {
        if (code == null) {
            return null;
        } else {
            T[] enums = (BaseEnum[])clazz.getEnumConstants();
            BaseEnum[] var3 = enums;
            int var4 = enums.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                T anEnum = var3[var5];
                if (anEnum.getCode() == code) {
                    return anEnum;
                }
            }

            return null;
        }
    }

 

posted @ 2022-02-18 16:44  八英里  阅读(67)  评论(0编辑  收藏  举报