Missing Return Statement?

后端 未结 6 1146
半阙折子戏
半阙折子戏 2021-01-25 20:52

This is my code. when I compile using bluej it highlights the last } and says missing return statement. I cant put void because it is a boolean. ANy ideas?

 p         


        
6条回答
  •  北海茫月
    2021-01-25 21:30

    return Statement must be always the last statement in the method

    public boolean runAJob()
        {
            boolean jobsFinished = false;
    
            Job firstJob = getCurrentJob();
    
            String jobName = firstJob.getName();
    
            int jobDuration = firstJob.getDuration();
    
            if (!myJob.isEmpty()&& jobDuration > 0 && jobDuration <= myTotalDuration)
    
            { 
    
                 myTotalDuration -= jobDuration;
    
                 myFinishedJobs.add(myJob.get(0));
    
                 myJob.remove(0);
    
                 System.out.println("'"+jobName+"'" +" is completed. "+ myTotalDuration+ " 
    

    seconds remaining on the clock");

                 jobsFinished = true;
    
            }
    
            else
    
            {
    
                System.out.println("JobQueue is empty");
    
            }
    
            return jobsFinished;
        } 
    

提交回复
热议问题