簡體   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