繁体   English   中英

Java通用接口“类型参数不在范围内”错误

[英]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.

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