简体   繁体   English

奇怪的行为覆盖方法。 我有错误

[英]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: 要真正深入研究这个问题,我建议:

  1. Inspect the classpath that you use for running the application to determine/confirm the location where the api jar is being used from. 检查用于运行应用程序的类路径,以确定/确认使用api jar的位置。
  2. Understand what sequence of events ensures that that jar gets refreshed with your latest built code. 了解什么事件顺序可以确保使用最新构建的代码刷新jar。 Perhaps you always need to invoke 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.

相关问题 Java 中的抽象方法即使被覆盖也可以具有默认行为吗? - Can an abstract method in Java have a default behavior even if it is overridden? 浮点方法的奇怪行为。 超载? - Odd behavior of a float method. Overloading? 标定方法时出错。 (java) - error in caling a method. (java) 方法getUploadedBlobs的异常行为 - Strange behavior with the method getUploadedBlobs 我通过调用 enqueueUniquePeriodicWork() 方法安排了定期工作。 如何获得结果? - I have scheduled a periodic work by calling the enqueueUniquePeriodicWork() method. How to get result? 我有四个方法的字符串值。 如何组合琴弦? - i have four string values from method. how to combine strings? 将抽象 class 作为参数类型传递,无法覆盖方法。 我对java中的多态性有什么误解吗? - Passing abstract class as type in parameter, unable override method. Do I have a misunderstanding of polymorphism in java? 用相同的方法在一个类中实现两个接口。 哪个接口方法被覆盖? - Implementing two interfaces in a class with same method. Which interface method is overridden? 在方法内部的if语句中使用递归时的奇怪行为。 Java的 - Strange behaviour when using recursion in an if statement, inside a method. Java Ant JUnit错误没有可运行的方法。 initializeError - Ant JUnit Error No runnable method. initializationError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM