子类不能调用父类的公共方法

时间:2018-06-27 12:09:46

标签: java inheritance abstract-class

我有一个名为 {"title":"Test","msg":"test"} token: ["pid_58cc-6fed***"] key:AA*****zEoEbsgPZCjK_umqrmgMZRkpyN7BAA5MNfGuojQP5olWIe1H_vzU8-9THNcB-CgZAjA6fwL72yE******6V7Cl-IObLDGwA6SqTopuK96begUtysy_cG8rc02vdIeYx**** 的抽象类,它实现了接口FooBar确实为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个方法(FooBarnullSafeGet):

nullSafeSet

1 个答案:

答案 0 :(得分:1)

nullSafeGet(...)nullSafeSet(...)不是在抽象类中实现的,而是重载的:它们没有相同的参数类型,例如SessionImplementor而不是SharedSessionContractImplementor