I have the following interface:
public interface SingleRecordInterface<T> { public void insert(T object); }
I have the abstract class below (that does not mention the method insert):
public abstract class AbstractEntry implements SingleRecordInterface<AbstractEntryBean> { }
I have the concrete class:
public class SpecificEntry extends AbstractEntry { public void insert(SpecificEntryBean entry) { // stuff } }
Finally, SpecificEntryBean is defined as:
public class SpecificEntryBean extends AbstractEntryBean { }
I have the following error:
The type SpecificEntry must implement the inherited abstract method SingleRecordInterface.insert(AbstractEntryBean)
I don't understand the reason for this error, given that SpecificEntryBean extends AbstractEntryBean. How do I fix this error?
An abstract class defines the identity of a class. An interface can inherit multiple interfaces but cannot inherit a class. An abstract class can inherit a class and multiple interfaces.
An abstract class cannot be inherited by structures. It can contain constructors or destructors. It can implement functions with non-Abstract methods. It cannot support multiple inheritances.
Only generic classes can implement generic interfaces. Normal classes can't implement generic interfaces.
You need to make your abstract class generic as well:
public abstract class AbstractEntry<T extends AbstractEntryBean> implements SingleRecordInterface<T> { }
Then for your concrete class:
public class SpecificEntry extends AbstractEntry<SpecificEntryBean> { }
Change to the following:
public abstract class AbstractEntry<EB extends AbstractEntryBean> implements SingleRecordInterface<EB> { }
and
public class SpecificEntry extends AbstractEntry<SpecificEntryBean> { public void insert(SpecificEntryBean entry) { // stuff } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With