EDIT: This is just a tiny snippet of the code if you have any questions I can post more.
Trying to write a process scheduling algorithm in Java using Queues and I am running into this warning. Can anyone help me fix this warning?
prog2.java:115: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Collection
notSubmitted.add(p[r]);
Here is the code that I am having trouble with. I think I need to use Generics but I haven’t used them before.
static Queue notSubmitted = new LinkedList();
...
for(int j = 0; j < numProcesses; ++j)
{
pid = i.nextInt();
priority = i.nextInt();
submissionTime = i.nextInt();
totalCpuTime = i.nextInt();
computeTime = i.nextInt();
ioTime = i.nextInt();
p[j] = new Process(pid, priority, submissionTime, totalCpuTime, computeTime, ioTime);
}
for(int r = 0; r < numProcesses; ++r)
{
//populate the not submitted queue first
notSubmitted.add(p[r]);
}
To get rid of the warning, you can use generics in your queue declaration as follows (Java 5 & 6):
or if you use Java 7+:
That tells the compiler that you only plan to add
Processobjects to that list.