Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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();
    }
}
share|improve this answer
    
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 '12 at 19:03
    
I've tested the answer that I gave and it compiles handily. Have you tried it just as I posted? –  Kyle Mar 22 '12 at 19:11
1  
I'll add, don't always trust the eclipse compiler, double check that javac is producing the same answer from the CL –  Martijn Verburg Mar 22 '12 at 19:25
    
I commented before you showed the code example, yes it works, thanks! –  dasen Mar 24 '12 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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