[英]Java interface inherits from two other interfaces - is it possible to, by using Java reflection, remove information about one of the interfaces?
我有這個特定的要求,因為第三方庫以某種方式具有這個interface A
,它extends B
,而后者又extends C, D
。
現在,問題是interface C extends D
。 IMO,因為C
已經擴展了D
, B
應該只extends C
。
當我嘗試使用interface A
類型的對象在 Vaadin Flow 中綁定表單時出現問題。 錯誤消息是: Duplicate key found for property [this common method]
。
我檢查了對象並注意到有以下層次結構:
// myObject:
// reflectionData:
// referent:
// interfaces:
// [0]:
// name: "com.example...." [interface B from above]
// reflectionData:
// referent:
// interfaces:
// [0]:
// name: "com.example..." [interface C from above]
// [1]:
// name: "com.example..." [interface D from above]
我的想法是以某種方式,通過使用 Java 反射,在將對象發送到 Vaadin 的Binder
類之前,刪除數組的第二個元素( interface D
)(如果可能的話)。
您不能在 Java 中修改反射信息。 但其實是Vaadin的一個bug,提交bug報告。 在 Java 中,具有相同名稱(和參數)的接口方法不被視為重復 - 它是相同的方法。 當java編譯器懷疑時,它會發出錯誤。 如果您的程序已編譯,則它是正確的,並且 Vaadin 必須與任何正確的程序一起工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.