Grokking Java Interview Questions
0% completed
var, Text Blocks, and Switch Expressions
var status = "PAID"; String label = switch (status) { case "NEW", "PAID" -> "open"; default -> "closed"; }; String receipt = """ Order 1001 total 2400 """;
None of these statements compiles on Java 8. The first leaves out a type, the second assigns the result of a switch, and the third writes a string over several lines.
Four questions about them follow: where the compiler accepts var, which spaces of a text block remain in the string, how a switch becomes a value, and which instructions the compiler generates for it.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%