Why if (arg0.length > 0 && arg0[0].equals(“exitcode”))?

好久不见. 提交于 2019-12-23 02:47:14

问题


I found this SpringBoot Application code which throws Exit Code 10 when executed with argument "exitcode".

public class Swagger2SpringBoot implements CommandLineRunner {

    @Override
    public void run(String... arg0) throws Exception {
        if (arg0.length > 0 && arg0[0].equals("exitcode")) {
            throw new ExitException();
        }
    }

    public static void main(String[] args) throws Exception {
        new SpringApplication(SpringBootEntityApp.class).run(args);
    }

    class ExitException extends RuntimeException implements ExitCodeGenerator {
        private static final long serialVersionUID = 1L;

        @Override
        public int getExitCode() {
            return 10;
        }

    }

}

Running this code with the given argument exits the program.

java -jar exitcode arg1 arg2 

I would be grateful if somebody could explain the use-case of this code.

PS: Why are we running the program to exit the program.

References:

  1. Swagger Petstore.

  2. Plaza Client

  3. Yidi

  4. Stack Overflow Question 1

  5. Docker Dash

来源:https://stackoverflow.com/questions/58618988/why-if-arg0-length-0-arg00-equalsexitcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!