У меня есть абстрактный класс Foo
, который реализует интерфейс Bar
. Foo
предоставляет public
реализации для Bar
s методов.
Теперь у меня есть класс FooBar
, который расширяет Foo
. Как ни странно, теперь я должен реализовать интерфейс Bar
в FooBar
. Следующее, что странно для меня, это то, что я просто не могу вызвать super.barMethod()
в FooBar
, так как это приводит к следующей ошибке:
Невозможно напрямую вызвать абстрактный метод barMethod для типа Bar
Что делает это еще более странным тот факт, что Bar
имеет более 10 методов, но мне нужно реализовать только 2 в FooBar
.
Есть идеи, почему это происходит и как это исправить?
Код:
Класс Foo:
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;
}
Текущий FooBar
класс, который должен реализовывать 2 метода (nullSafeGet
и nullSafeSet
):
public class FileTransferJobUserType extends
PersistentEnumUserType<FileTransferJob> {
}