Java definition: tag, token
I wrote this:
(fitness>g.fitness) ? return 1 : return -1;
And received the following error:
Syntax error on token, not tag
Anyone can explain what tokens and tags are in this case?
Editor: Thank you for fixing my code, but can you explain what tokens and tags are for future reference?
Solution
A tag is a single character and string with a certain meaning
The tokens defined in Chapter 3: musical structure of the Java language specification are:
The tags in the given row are:
"(","fitness",">","g.fitness",")","?","return","1",":","-1",";"
(whitespace is also important, but I omitted them from above.)
Tags in Java are used to control the flow in the program and are identifiers followed by colons
An example of a tag is hello:
Tags are used with continue and break statements to specify the control structure to continue or break
For more information about label declarations, see section 14.7.1 of the Java language specification
The problem here is the return statement:
(fitness>g.fitness) ? return 1 : return -1; ^^^^^^
One: immediately after returning 1, this makes the compiler think there should be a label there
However, returning 1 itself is a statement, so there is no label identifier, so the compiler complains that it expects a label, but it can't find the correctly formed label
(fitness>g.fitness) ? return 1 : return -1; ^^^^^^^^ ^ statement label without an identifier