Skip Top Navigation Bar

Java Patterns and Unnamed Variables


Allows us to use the underscore ( _ ) for variable names that will not be used. In the following code for try... catch statements, an Exception variable is not used, so we can write:

In another example, using Pattern Matching for Switch, we can print the animals' names using the following:

Since we are using a sealed interfaces that only allows implementation with Dog and Cat, a default statement is not necessary.