[英]strange behavior overridden method. I have ann error
I have some module in OSGi project. 我在OSGi项目中有一些模块。
payment
- payment-api
- payment-impl
in payment-api
I have interface UserService
在
payment-api
我有接口UserService
public interface UserService{
String method1(String p1, int p2);
String method2(String p1);
}
And implementation 和实施
public class UserServiceImpl implements UserService{
@Override
public String method1(String p1, int p2){
//code
returnt result;
}
@Override
public String method2(String p1){
//code
returnt result;
}
}
And my module payment-impl
has dependency 而且我的模块
payment-impl
具有依赖性
<dependency>
<groupId>mydomain</groupId>
<artifactId>payment-api</artifactId>
<version>1.0.0</version>
</dependency>
It work fine. 工作正常。 But now, if i tried add new mrthod to
UserService
and after override this method in UserServiceImpl
I have error: 但是现在,如果我尝试将新的方法添加到
UserService
并在UserServiceImpl
覆盖此方法后出现错误:
public interface UserService{
String method1(String p1, int p2);
String method2(String p1);
String test(int a);
}
and 和
@Override
public String test(int a) {
return "sdfsdff";
}
java:[94,9] method does not override or implement a method from a supertype
But if I delete @Override
annotation all work fine. 但是,如果我删除
@Override
注释,则一切正常。 I cn not understand why? 我cn不明白为什么? how can this be?
怎么会这样?
interface Y{
String method();
}
public class X implemets Y{
@Override
String method(){
return "some string";
}//is error
//------
String method(){
return "some string";
}//is fine
}
And if I not implements this method compiler swears. 如果我不实现此方法,则编译器会发誓。 And by default IDE override methosd with annotation.
默认情况下,IDE用注解覆盖methosd。 And another methods which have already been implemented work fine without annotations
另外,已经实施的另一种方法也可以正常工作而无需注释
The impl
module might be referencing a stale version of the api
module. impl
模块可能引用了api
模块的陈旧版本。 You might want to rename your version 1.0.0-SNAPSHOT
, clear your local maven repository (typically found in ~/.m2/repository
), and then clean and rebuild the product. 您可能想重命名
1.0.0-SNAPSHOT
版本,清除本地maven存储库(通常在~/.m2/repository
),然后清理并重建产品。
I am uncertain whether suffixing the version with SNAPSHOT
is important here, but it is not a bad practice to do so while the product is in development. 我不确定在此处添加
SNAPSHOT
版本是否很重要,但是在产品开发过程中这样做并不是一个坏习惯。
I am also uncertain exactly why you might have hit a stale version of the module. 我也不确定为什么您会遇到该模块的过时版本。 To really dig deep into the problem I would recommend:
要真正深入研究这个问题,我建议:
mvn install
and cannot just rely on the IDE compilation process, that I'm not sure. mvn install
并且不能仅仅依靠IDE编译过程,我不确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.