0

So I'm creating an implementation of a priority queue using generics. I have this interface which I am trying to implement in my PriorityQueue class:

public interface PriorityQueueInterface<Item extends Comparable<Item>> { } 

but I'm not sure what the proper syntax is to correctly implement the PriorityQueueInterface. Here is what I currently have:

public class PriorityQueue<Item extends Comparable<Item>> implements PriorityQueueInterface<Item extends Comparable<Item>>{ } 

but it's throwing multiple errors. What would be the correct way to implement the interface? Any help would be appreciated.

2
  • You have to make the distinction between a type variable/parameter and a type argument. Commented Sep 24, 2014 at 19:20
  • 1
    for best results use <Item extends Comparable<? super Item>> Commented Sep 25, 2014 at 1:46

1 Answer 1

1

You've already declared Item to be Comparable<Item> with the class definition of PriorityQueue. You only need to reference it in the implements clause, where you don't need to repeat that it's Comparable<Item>. You reference a generic type parameter in the implements or extends clause just as you would for any other part of the class body where the generic type parameter is in scope.

Try

public class PriorityQueue<Item extends Comparable<Item>> implements PriorityQueueInterface<Item>{ /* implement here */ } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.