我需要在接口(interface)中使用两个具有相同名称但不同命名空间的类(foo.request.Response
和 bar.request.Response
)。在类中,这可以通过使用带有命名空间的全名来实现:
public foo.request.Response method1() { [...]
public bar.request.Response method2() { [...]
但这似乎在接口(interface)中不起作用。
处理这个问题的正确方法是什么?
编辑 1 错误来自 Eclipse:
foo cannot be resolved to a type
接口(interface)代码:
public interface ITestController {
String method1(foo.request.Response response);
}
我发现了这个问题,它不是来自界面,而是依赖项中的一个简单困惑。感谢您的帮助;)
最佳答案
它适用于接口(interface),但应注意实现类以相同的方式完全限定名称。
请注意,在实现接口(interface)时,您不能选择两个类中的哪一个。 接口(interface)指定在实现接口(interface)时使用两个类中的哪一个。
您在答案中发布的代码很困惑。如果前两个方法属于实现 ITestController
的类,则该类还必须包含一个实现
public String method1(foo.request.Response response) { ... }
关于Java - 在接口(interface)中使用两个同名的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278359/