Today I learned that it looks like the Java Playground uses JShell. I knew it didn’t require a class/main method wrapper.
The reason I discovered this was because of the following code:
Consumer p = (p) -> {int var = 3; var++; return;};
In my IDE or at the command line, this code gives an error
Lambda.java:2: error: variable p is already defined in method main()
Consumer p = (p) -> {int var = 3; var++; return;};
In JShell and Java Playground, it happily compiles. This matters because I was told that the flashcards with my book has an errata and that “p” is just fine.
The Java Language specification writes about shadowing:
It is a compile-time error if the name of a formal parameter is used to declare a new variable within the body of the method, constructor, or lambda expression, unless the new variable is declared within a class or interface declaration contained by the method, constructor, or lambda expression
Lesson to readers: don’t use jshell when studying for the exam.