Jameshobbs
Jameshobbs

Reputation: 524

Bound mismatch: type is not a valid substitute for the bounded parameter

I am getting the following error Bound mismatch: The type FFTWTask is not a valid substitute for the bounded parameter <T extends AbsTask<T>> of the type AbsStage<T,U>

I am representing an abstract stage:

public abstract class AbsStage<T extends AbsTask<T>, U extends AbsTask<U>> { }

Where an AbsTask is:

public abstract class AbsTask <T> { }

Then I create an AbsTask called FFTWTask:

public class FFTWTask extends AbsTask<Double>{ }

Finally, I create an AbsStage called FFTWStage:

public class FFTWStage extends AbsStage<FFTWTask, FFTWTask>{ } // Error occurs here

What am I missing with my understanding of generics. I have found numerous posts that feature the same error message, but I cant seem to decipher them.

Here is a simple class that achieves the error:

public class Test {
  public abstract class AbsTask <T> { }
  public class FFTWTask extends AbsTask<Double>{ }

  public abstract class AbsStage<T extends AbsTask<T>, U extends AbsTask<U>> { }
  public class FFTWStage extends AbsStage<FFTWTask, FFTWTask>{ } // Error here <-
}

Upvotes: 2

Views: 4845

Answers (1)

August
August

Reputation: 12558

If the type parameter T in AbsStage must extend AbsTask<T>, then FFTWTask must extend AbsTask<FFTWTask> in order to be used in FFTWStage:

public class FFTWTask extends AbsTask<FFTWTask>{ }

Upvotes: 2

Related Questions