Discussion
This puzzle’s first line of code is an unfinished enum class declaration that’s missing its name and body. So why doesn’t the compiler reject it?
A class declaration doesn’t end at the first line break—it can span multiple lines, continuing until the compiler determines that it’s syntactically complete. The formatting makes it look like private is the start of a new declaration, but in fact, it’s the end of the first one and acts as our missing class name.
A class doesn’t require a body and doesn’t need to end with a final line break. That means enum class private is a complete and valid declaration that can be immediately followed by another class.
Out of Context
If you’ve written code in other programming languages, you might be used ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access