Generics, Comparable and asbtract classes

Discussion in 'Java' started by Bowbaq, Mar 23, 2010.

  1. Bowbaq

    Bowbaq

    Joined:
    Mar 23, 2010
    Messages:
    2
    Hello.

    As I found numerous answers here already, I think it's a good place to ask my question. After a couple hours googling, I found nothing so ...

    As a mini project for my studdies, I have to implement a prioritized queue in Java. One of my implementations lays on a binary heap. As it needs a comparison method to keep it's heap properties, here is what I did :
    Code:
    public class BinaryHeap<T extends Comparable<T>> {
    ...
    }
    
    I also use an abstract class Element<T> to factorize code for my various implementations :

    Code:
    public abstract class Element<T> implements Comparable<Element<T>> {
    
            private T content;
            private double priority;
    
            public int compareTo(Element<T> e) {
    		return (int) (priority - e.getPriority());
    	}
    ...
    }
    
    I want to inherit this class like the folowing, and use those HeapElement<T> in my heap described before.
    Code:
    public class HeapElement<T> extends Element<T>{
    
    	public ElementTas(T content, double priority) {
    		super(content, priority);
    	}
    }
    
    When I try something like this :
    Code:
    BinaryHeap<HeapElement<T>> heap;
    
    I get this error :
    And if I try this :
    Code:
    public class HeapElement<T> extends Element<T> implements Comparable<HeapElement<T>>{
    
    	public ElementTas(T content, double priority) {
    		super(content, priority);
    	}
    }
    
    I get this error ...
    So I must say I'm a bit confused. The first error seems to indicate that the Comparable interface isn't implemented. And the second tells me that it is indeed.

    Any hint please?

    P.S I'm french, so please forgive me if I'm being unclear...
     
    Last edited: Mar 23, 2010
    Bowbaq, Mar 23, 2010
    #1
    1. Advertising

  2. Bowbaq

    Bowbaq

    Joined:
    Mar 23, 2010
    Messages:
    2
    Anyone please?
    Bump!
     
    Bowbaq, Mar 25, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bergholt

    Generics and Comparable

    Bergholt, Nov 27, 2004, in forum: Java
    Replies:
    3
    Views:
    6,055
    Bergholt
    Nov 30, 2004
  2. Juergen Berchtel
    Replies:
    1
    Views:
    6,008
    John C. Bollinger
    May 20, 2005
  3. Ron Albright

    Generics & Comparable

    Ron Albright, Oct 5, 2006, in forum: Java
    Replies:
    3
    Views:
    414
    Hendrik Maryns
    Oct 6, 2006
  4. Roedy Green
    Replies:
    6
    Views:
    804
    Roedy Green
    May 22, 2008
  5. neuneudr@yahoo.fr

    generics and Comparable compiler warning

    neuneudr@yahoo.fr, Jan 14, 2009, in forum: Java
    Replies:
    2
    Views:
    399
    neuneudr@yahoo.fr
    Jan 14, 2009
Loading...

Share This Page