javaenum多字段_如何确保多个JavaEnum类型实现了相同的
功能
我在Mybatis中使⽤这些代码
public interface MyCustomTestInterface {
getValue();
/* cannot override getInstance()*/
/*static Object getInstance(T);*/
}
public enum MyTestInt implements MyCustomTestInterface {
TEST_INT(5);
private Integer value;
@Override
public Integer getValue() {
return this.val;
}
public static MyTestInt getInstance(Integer value) {
// find MyTestInt using value
}
}
public enum MyTestStr implements MyCustomTestInterface {
TEST_STRING("TEST");
private String value;
@Override
public String getValue() {
return this.val;
}
public static MyTestStr getInstance(String value) {
// find MyTestStr using value
}
}
@MappedTypes(value = {MyTestInt.class, MyTestStr.class})
public class MyCustomEnumTypeHandler & MyCustomTestInterface/*syntax error*/> extends BaseTypeHandler {
private Method getInstance;
public MyCustomEnumTypeHandler(Class type) throws NoSuchMethodException {
// do something
}
// get a Enum type using Integer OR String(from database to java Enum object)
@Override
public E getNullableResult(ResultSet rs, String columnName) throws SQLException {
// do somethingenum c++
Object value = rs.getObject(columnName);
return (E)getInstance.invoke(null, (T)value/*syntax error*/);
}
}我的问题:
1.如何让Enum类型实现MyCustomTestInterface必须具有getInstance()函数?
2.如何使MyCustomEnumTypeHandler声明正确,修复⼏个“语法错误”,我想要⼀个通⽤的枚举类型hander 提前致谢
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论