繁体   English   中英

方法实现后泛型方法的接口

[英]interface for generic method after method implemented

我目前的情况是:

  • 我有 2 个 maven 模块
  • 模块 1 一般带有接口
  • 具有实现的模块 2,并且具有不同 maven 模块模块 3(外部项目模块)的特定依赖性
  • 模块 2 具有模块 1 的依赖项
  • 模块 1 不允许有模块 3 的依赖
  • 在模块 2 中,我有一个实现接口的方法,该接口继承自 maven 工件,我无法更改
  • 我需要提供一个带有 module1 中方法签名的接口,我已经在 module2 中实现了该接口,显然还有其他特定方法签名的指定实现。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM