[英]Why a generic method of an interface can be implemented as non-generic in Java?
[英]interface for generic method after method implemented
我目前的情况是:
module2 中实现的方法签名如下所示:
Class MyClass{
public <T extends Enum<T> & Interface1> Interface2 myMethod(param1, param2...){.....}
}
Interface1 和 Interface2 是 module3 的一部分(我不能修改并且 module1 不能将其作为依赖项)
问题是:如何在 module1 中创建一个接口,由 MyClass 表单模块 2 实现,并具有所需的方法签名?
就像是:
模块1:
interface MyInterface{
<T extends Enum<T> & -->What I should put here<--- > -->What I should put here<--- myMethod(param1, param2...){.....}
}
class MyClass implements MyInterface{
public <T extends Enum<T> & Interface1> Interface2 myMethod(param1, param2...){.....}
}
class MyClass2 implements MyInterface{
public <T extends Enum<T> & -->Different interface needed here than Interface1<-- > -->Different interface needed here than Interface2<-- myMethod(param1, param2...){.....}
}
有任何想法吗? 我如何克服从 module3 继承的接口(我无法更改也不能将其作为 module1 中的依赖项,只有在 module2 中我可以将其作为依赖项)基本上是在 module1 中提供更通用的接口方法签名定义以满足module2中方法的签名?
目前它说:两种方法:接口方法和 class 实现的方法具有相同的擦除,但都没有覆盖另一个。
使用推理:
<A, B, T extends Enum<T> & A> B myMethod(param1, param2...){.....}
并让呼叫站点弄清楚。
恕我直言,当事情变得如此粗糙时,generics 被高估了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.