For the following segment of java code, the method of “run” occurs four times. I am quite confusing about the relationships of these four occurrences of “run”. Can you explain this to me? The original code is pretty long, I just keep the part that is related to my question.

public final class Job extends AbstractJob {
  private Job( ) {
  }
  public static void main(String[] args) throws Exception {  
           new Job( ).run(new Path("testdata"), output, 10 );
  }

  @Override
  public int run(String[] args) throws IOException, ClassNotFoundException,   InterruptedException {
        run(input, output, alpha0);
        return 0;
  }  
  public void run(Path input,  Path output,  double alpha0)
    throws IOException, ClassNotFoundException, InterruptedException {    
    ClusterDriver.run(directoryInput, output, alpha0);    
  }
}

The two of run methods appear to be overloads. They have different parameter lists. I don't know why the author reused the name because run() has a special usage in many classes.
Otherwise run is just another method name. You need to read the API doc for each class to see what they do.

I'm not familiar with the AbstractJob class. Does it define these methods as posted here? One of the methods has the @Override statement before it because it should override the run() method defined in the super class.

I wonder if this code would work as well as what you posted:

public final class Job extends AbstractJob {
  private Job( ) {
  }
  public static void main(String[] args) throws Exception {  
           new Job( ).runXXX(new Path("testdata"), output, 10 );
  }

  @Override
  public int run(String[] args) throws IOException, ClassNotFoundException,   InterruptedException {
        runXXX(input, output, alpha0);
        return 0;
  }  
  public void runXXX(Path input,  Path output,  double alpha0)
    throws IOException, ClassNotFoundException, InterruptedException {    
    ClusterDriver.run(directoryInput, output, alpha0);    
  }
}

Edited 5 Years Ago by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.