無論如何,我已經給了一個類和一個PriorityQueueInterface來實現一個Linked Node PriorityQueue。但是,我無法掌握類的類型。 這裏是入門級這是什麼意思<E,P擴展可比較的<? super P>>?
我只是不知道如何開始任務而不知道這意味着什麼。
public class Entry<E, P extends Comparable<? super P>>
implements Comparable<Entry<E, P>>
{
private E theItem;
private P thePriority;
public Entry(E item, P priority)
{
theItem = item;
thePriority = priority;
}
public E getItem()
{
return theItem;
}
public P getPriority()
{
return thePriority;
}
public int compareTo(Entry<E, P> other)
{
return thePriority.compareTo(other.thePriority);
}
public String toString()
{
return "item/priority <" + theItem + ", " + thePriority + ">";
}
}
這裏是接口
public interface PriorityQueueInterface<T extends Comparable<? super T> > {
/** Adds a new entry to this priority queue.
* @param newEntry An object to be added */
public void add(T newEntry);
/** Removes and returns the entry having the highest priority.
* @return Either the object having the highest priority or
* if, the priority queue is empty before the operation, null. */
public T remove();
/** Retrieves the entry having the highest priority.
@return Either the object having the highest priority or,
if the priority queue is empty, null. */
public T peek();
/** Detects whether this priority queue is empty.
@return True if the priority queue is empty, or false otherwise. */
public boolean isEmpty();
/** Gets the size of this priority queue.
@return The number of entries currently in the priority queue. */
public int getSize();
/** Removes all entries from this priority queue. */
public void clear();
}// End of PriorityQueueInterface
你對泛型有一些想法嗎?佩奇? –