Reputation: 29314
I have a custom "Heap" class:
public class Heap<T extends Comparable<T>>
{
ArrayList<T> heapList;
public Heap()
{
heapList = new ArrayList<T>();
}
and a custom "Process" class:
public class Process {
private int processID, timeUnitsRequired, priority, timeOfArrival;
public Process(int processID, int timeUnitsRequired, int priority, int timeOfArrival) {
this.processID = processID;
this.timeUnitsRequired = timeUnitsRequired;
this.priority = priority;
this.timeOfArrival = timeOfArrival;
}
But if I try to make a new Heap of Processes, like Heap<Process> processHeap = new Heap<Process>();
I get the following error:
Bound mismatch: The type Process is not a valid substitute for the bounded parameter > of the type Heap
Why is this? I can't seem to figure it out.
Upvotes: 0
Views: 41
Reputation: 94459
The process object needs to implement the Comparable
interface.
Example Implementation Comparing by Priority
public class Process implements Comparable<Process>{
@Override
public int compareTo(Object o) {
Process p2 = (Process) o;
if(this.priority > p2.priority){
return 1;
}else if(this.priority < p2.priority){
return -1;
}
return 0;
}
}
Upvotes: 1