0

I seems to be running into a compilation error with a generic interface. The goal is to create an interface for use in my test classes the defines the common methods of a domain class and a generated DTO class. I did some digging and none of the answers I have found so far seem applicable to what I am trying to do. Most of the answers either refer back to this: class not within type bounds or they suggest using wildcards which is not an option here.

When I try to compile, I get the following error:

[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

My class structure looks like this:

interface IBrand<T extends ISubCollection>

interface ISubCollection

class Brand<T extends SubCollection>
    extends Entity
    implements IBrand<T>

class SubCollection
    extends Entity
    implements ISubCollection

The generated DTO classes look like:

class SubCollectionDto
    implements ISubCollection

class BrandDto<T extends SubCollectionDto>
    implements IBrand<T>

I'm really racking my brain trying to understand what I am doing wrong here. Any help would be greatly appreciated.

ruakh
  • 175,680
  • 26
  • 273
  • 307
pbuchheit
  • 1,371
  • 1
  • 20
  • 47
  • Can you get rid of your class bodies? They are irrelevant to the problem, and make it impossible to read on a small screen. – Andy Turner Nov 08 '17 at 17:34
  • 2
    Compiles fine for me on 1.8. – tsolakp Nov 08 '17 at 17:56
  • I'm currently using 1.7 if that makes any difference. The strange thing is, I don't get any errors from eclipse. It only gives me an error when I compile using ant – pbuchheit Nov 08 '17 at 18:33

1 Answers1

0

I think I finally figured it out. It was actually a classpath issue that had nothing to do with the generics. When I originally set up the DTO classes they were under the 'src' directory. I later moved them into a different directory, but apparently the old folder never got removed. So eclipse was looking at the current, correct set of files while ant was looking at the old directory. No idea why that was causing the error message I saw, but it is working now.

pbuchheit
  • 1,371
  • 1
  • 20
  • 47