High school programming project, (COMPLETE BEGINNER)

In its most basic form, an enum is just labels that we can store in a variable:

The code above declares a variable called state of datatype GameState and initializes it w/ the “label” MENU.

The idea is that depending on the “label” currently stored in the variable state should determine which “action” the code has to take; for example, the switch () {} block within draw().

A Java lambda is an alternative syntax to declare a function in the form of an expression.

On the code above, (a, b) -> b.score - a.score is a lambda function which is passed as the argument to the method sort().

Method sort() will call back that lambda many times as a “rule” on how we want the List highScores to be sorted.

In that case, the “rule” is to sort the List in descending order based on the field score from class ScoreEntry.

More precisely within the lambda, its parameter a represents 1 ScoreEntry, which is then compared to the 2nd parameter b, which is also a ScoreEntry instance.

By subtracting their corresponding score fields, we’ll get either a positive value, or a negative value or a zero value.

A positive result means that b should be positioned before a within the List.

A negative result means that b should be positioned after a within the List.

While a zero 0 result means both b & a have the same score; and thus no changes are needed.

BtW, a Java lambda function automatically returns the result of the expression within its body.