1

In the following code how do i pass proc to execute function as a reference so that after the function is executed its value is updated

public Process executeProcess(Process proc)
    {
        int remain=proc.getRemainingTime();
        if(remain-timeQuantum<=0)
        {
            proc.setRemainingTime(0);
            proc.setStatus(2);//2 represents terminated
            proc.setFinishTime(time);
            time=time+remain;
        }
        else {
            proc.setBurstTime(remain-timeQuantum);
            time=time+timeQuantum;
            proc.setStatus(1);// 1 represents waiting
            }
        return proc;
    }
    public ArrayList<Process> FCFS()
    {
        Process running;
        procList.sort(Comparator.comparing(Process::getArrivalTime));
        for(Process proc:procList) {
        running=executeProcess(proc);

        }
        return procList;
    }
  • 5
    tl;dr: yo cannot. Possible duplicate of [Is Java "pass-by-reference" or "pass-by-value"?](https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value) – Turing85 Jul 28 '19 at 20:58
  • What makes you think that it doesn't do that already? `Process` is a class. Any variable that refers to it is already a reference. You are passing the value of a reference, which is for all intents and purposes the same as the original reference) – Tibrogargan Jul 28 '19 at 20:59
  • Don't call it functions, call it *methods*. – MC Emperor Jul 28 '19 at 21:02

0 Answers0