我有一个名为 {"title":"Test","msg":"test"}
token: ["pid_58cc-6fed***"]
key:AA*****zEoEbsgPZCjK_umqrmgMZRkpyN7BAA5MNfGuojQP5olWIe1H_vzU8-9THNcB-CgZAjA6fwL72yE******6V7Cl-IObLDGwA6SqTopuK96begUtysy_cG8rc02vdIeYx****
的抽象类,它实现了接口Foo
。 Bar
确实为Foo
的方法提供了public
的实现。
现在我有了扩展Bar
的类FooBar
。奇怪的是,我现在必须在Foo
中实现Bar
接口。接下来令我感到奇怪的是,我无法在FooBar
中调用super.barMethod()
,因为这会引发以下错误:
不能直接为Bar类型调用抽象方法barMethod
更奇怪的是,FooBar
有10种以上的方法,但我只需要在Bar
中实现2种方法。
有什么想法为什么会发生以及如何解决?
代码:
Foo类:
FooBar
public abstract class PersistentEnumUserType<T extends PersistentEnum>
implements UserType {
/** The persistent enum type */
private Class<T> persistentClass;
@SuppressWarnings("unchecked")
public PersistentEnumUserType() {
this.persistentClass = (Class<T>) findParameterizedType(getClass())
.getActualTypeArguments()[0];
}
private ParameterizedType findParameterizedType(
@SuppressWarnings("rawtypes") Class clazz) {
if (clazz == null) {
return null;
}
Type type = clazz.getGenericSuperclass();
if (type instanceof ParameterizedType) {
return (ParameterizedType) type;
}
return findParameterizedType(clazz.getSuperclass());
}
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}
public Object deepCopy(Object value) throws HibernateException {
return value;
}
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}
public boolean equals(Object x, Object y) throws HibernateException {
return x == y;
}
public int hashCode(Object x) throws HibernateException {
return x == null ? 0 : x.hashCode();
}
public boolean isMutable() {
return false;
}
public Object nullSafeGet(ResultSet rs, String[] names,
SessionImplementor session, Object owner)
throws HibernateException, SQLException {
int id = rs.getInt(names[0]);
if (rs.wasNull()) {
return null;
}
for (PersistentEnum value : returnedClass().getEnumConstants()) {
if (id == value.getCode()) {
return value;
}
}
throw new IllegalStateException("Unknown "
+ returnedClass().getSimpleName() + " id");
}
public void nullSafeSet(PreparedStatement st, Object value, int index,
SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.INTEGER);
} else {
st.setInt(index, ((PersistentEnum) value).getCode());
}
}
public Object replace(Object original, Object target, Object owner)
throws HibernateException {
return original;
}
public Class<T> returnedClass() {
return persistentClass;
}
public int[] sqlTypes() {
return new int[] { Types.INTEGER };
}
}
界面:
Bar
当前的public interface UserType {
int[] sqlTypes();
Class returnedClass();
boolean equals(Object x, Object y) throws HibernateException;
int hashCode(Object x) throws HibernateException;
Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException;
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException;
Object deepCopy(Object value) throws HibernateException;
boolean isMutable();
Serializable disassemble(Object value) throws HibernateException;
Object assemble(Serializable cached, Object owner) throws HibernateException;
Object replace(Object original, Object target, Object owner) throws HibernateException;
}
类应实现2个方法(FooBar
和nullSafeGet
):
nullSafeSet
答案 0 :(得分:1)
nullSafeGet(...)
和nullSafeSet(...)
不是在抽象类中实现的,而是重载的:它们没有相同的参数类型,例如SessionImplementor
而不是SharedSessionContractImplementor