What is this syntax in Java? I do not understand this

This is a syntax question.

I looked at some open source files, and I came across some syntax that I cannot recognize, and I was hoping you could clear it.

(This is taken from Main.java in the Rhino debugger here )

public static String[] processOptions(String args[])
    {
        String usageError;
        goodUsage: for (int i = 0; ; ++i) {
            if (i == args.length) {
                return new String[0];
            }
            String arg = args[i];
            if (!arg.startsWith("-")) {
                processStdin = false;
                fileList.add(arg);
                String[] result = new String[args.length - i - 1];
                System.arraycopy(args, i+1, result, 0, args.length - i - 1);
                return result;
            }
            if (arg.equals("-version")) {
                if (++i == args.length) {
                    usageError = arg;
                    break goodUsage;
                }
                int version;
                try {
                    version = Integer.parseInt(args[i]);
                } catch (NumberFormatException ex) {
                    usageError = args[i];
                    break goodUsage;
                }

My question is what goodUsage? What is the name of this syntax and what is it used for?

+3
source share
8 answers

These are shortcuts. They are used to break out of an indoor unit into a unit that is not the one that surrounds it.

Here is the relevant part of the Java Language Specification regarding labels.

, , 99% , ​​, , , , .

( , / , - JLS.)

+16

:

public class Main {
    public static void main(String[] args) {
        http://stackoverflow.com
        System.out.println("Does it?");
    }
}

?

: SO !

+4

- break , , goto, , Java "break to label" , .

+1

. , .

+1

, . wikepedia

0

Source: https://habr.com/ru/post/1721234/


All Articles