6

I have the following interfaces:

public interface Successorable<E> extends Comparable<E> 
    E suc();
}

and

interface IInterval <E extends Successorable<E>> {
    E min();
    E max();
}

I'm trying to implement IInterval by doing:

public class Interval<E> implements IInterval<E> {
 ....

However eclipse complains that the type E is not a valid substitute for the bounded parameter <E extends Successorable<E>> of the type IInterval<E>.

What am I doing wrong?

Thanks!

1 Answer 1

4

I believe you need to restate your conditions. The plain old E in Interval<E> doesn't necessarily fulfill E extends Successorable<E> so you need to be more specific about your parameter.

public class Interval<E extends Successorable<E>> implements IInterval<E> {
    @Override
    public E min() {
        throw new UnsupportedOperationException();
    }

    @Override
    public E max() {
        throw new UnsupportedOperationException();
    }
}
4
  • What do you mean by more specific? I tried to replace E with 'E extends Successorable<E>' but it doesn't work. I'm a newbie at this...
    – dasen
    Mar 22, 2012 at 19:03
  • I've tested the answer that I gave and it compiles handily. Have you tried it just as I posted? Mar 22, 2012 at 19:11
  • 3
    I'll add, don't always trust the eclipse compiler, double check that javac is producing the same answer from the CL Mar 22, 2012 at 19:25
  • I commented before you showed the code example, yes it works, thanks!
    – dasen
    Mar 24, 2012 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.