[英]Java Generic Interface 'Type Argument Not Within Bounds' Error
我似乎在使用通用接口時遇到編譯錯誤。 目的是創建一個用於我的測試類的接口,該接口定義域類和生成的DTO類的通用方法。 我做了一些挖掘工作,到目前為止發現的答案似乎都不適用於我嘗試做的事情。 多數答案要么返回到此: 類不在類型范圍內,要么建議使用通配符,這不是此處的選項。
當我嘗試編譯時,出現以下錯誤:
[uberCompile] BrandDto.java:10: error: type argument T#1 is not within bounds of type-variable T#2
[uberCompile] public class BrandDto<T extends SubCollectionDto> implements IBrand<T> {
[uberCompile]
[uberCompile] where T#1,T#2 are type-variables:
[uberCompile] T#1 extends SubCollectionDto declared in class BrandDto
[uberCompile] T#2 extends ISubCollection declared in interface IBrand
我的課程結構如下所示:
interface IBrand<T extends ISubCollection>
interface ISubCollection
class Brand<T extends SubCollection>
extends Entity
implements IBrand<T>
class SubCollection
extends Entity
implements ISubCollection
生成的DTO類如下所示:
class SubCollectionDto
implements ISubCollection
class BrandDto<T extends SubCollectionDto>
implements IBrand<T>
我真的在絞盡腦汁,試圖了解我在這里做錯了什么。 任何幫助將不勝感激。
我想我終於明白了。 實際上,這是一個與泛型無關的類路徑問題。 當我最初設置DTO類時,它們位於“ src”目錄下。 后來我將它們移到另一個目錄,但是顯然舊文件夾從未被刪除。 因此,eclipse在查看當前正確的文件集,而ant在查看舊目錄。 不知道為什么這導致了我看到的錯誤消息,但是現在可以正常工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.