我有这个公共抽象类MyClass的与抽象方法抽象的公共无效myMethod的()在我的Android库项目。不能覆盖超类的抽象方法时,子类是在另一个包
我想在另一个项目中构建这个类的具体实现,这是一个应用程序项目并引用了库项目。在子类中的方法实现标有“@覆盖”和Eclipse使我有以下错误:
The method myMethod() of type MySubClass must override or implement a supertype method
我删除“@覆盖”和错误变成警告:
The method MySubClass.myMethod() does not override the inherited method from MyClass since it is private to a different package
这说明什么意思?是的,这些类位于不同的项目和不同的包中,但这与继承有什么关系?两种方法都是公开的。
这里是超代码:
package com.emret.myPackage;
//Some imports here
public abstract class ThingsProvider {
//Class code here
abstract public void createThings();
}
这里是子类:
package com.emret.myPackage.subPackage;
//Some imports here
public class SmallThingsProvider extends ThingsProvider {
//Class code here
@Override
public void createThings() {
createThing(0, R.drawable.cat, R.raw.cat);
createThing(1, R.drawable.dog, R.raw.dog);
createThing(2, R.drawable.cow, R.raw.cow);
createThing(3, R.drawable.sheep, R.raw.goat);
createThing(4, R.drawable.bicycle, R.raw.bicycle);
}
}
你可以显示两个方法/类定义吗?这听起来像他们有不同的返回类型/参数。 – Thomas
你确定他们都是公开的吗?他们有'公共'关键字吗?这听起来像超类的方法是包私有的,如果没有关键字,这是默认的可见性。例如,'abstract void foo()'是包私有的,只能被同一包中的类覆盖。 – yshavit
@Thomas:我已经更新了问题以包含课程代码 –