Class UnnamedPatternsVariablesPreviewExamples
java.lang.Object
net.jrodolfo.java_evolution.java21.UnnamedPatternsVariablesPreviewExamples
Demonstrates unnamed patterns and variables as a Java 21 preview feature.
Sometimes Java syntax requires a variable name even though the program
intentionally ignores the value. Before this feature, developers often used
names such as ignored or unused. The underscore makes that
intent part of the language.
The feature became final in Java 22 as unnamed variables and patterns. This example uses JDK 25-compatible syntax.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanParseInteger(String text) Uses an unnamed catch parameter when the exception object is not needed.intcountWithoutUsingElements(Iterable<String> values) Uses an unnamed variable where the value is intentionally ignored.
-
Constructor Details
-
UnnamedPatternsVariablesPreviewExamples
public UnnamedPatternsVariablesPreviewExamples()
-
-
Method Details
-
countWithoutUsingElements
-
canParseInteger
Uses an unnamed catch parameter when the exception object is not needed.- Parameters:
text- numeric text- Returns:
- whether the text can be parsed
-