https://github.com/mechero/jdk12-switch-expressions
Example code of the Switch Expressions preview feature in Java 12
https://github.com/mechero/jdk12-switch-expressions
java java12 switch-expressions
Last synced: about 1 year ago
JSON representation
Example code of the Switch Expressions preview feature in Java 12
- Host: GitHub
- URL: https://github.com/mechero/jdk12-switch-expressions
- Owner: mechero
- Created: 2019-01-06T18:17:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-07T06:35:44.000Z (over 7 years ago)
- Last Synced: 2025-02-09T22:47:14.847Z (over 1 year ago)
- Topics: java, java12, switch-expressions
- Language: Java
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JDK 12 Switch Expressions Example
This project contains code examples comparing the classic Java switch statement with the new preview feature available in Java 12, Switch Expressions.
For the quick how-to and explanation, check out the article [Java 12 Switch Expressions in 5 minutes](https://thepracticaldeveloper.com/2019/01/07/java-12-switch-expressions-5-minutes/).
## Build with maven
First, make sure your JAVA_HOME variable points to a JDK 12 distribution, same as your PATH if needed.
To build the code and generate the JAR package using Maven, run:
`mvn clean package`
## Run from command line
From the project's root directory, you can run:
`java --enable-preview -jar target/jdk12preview-1.0.0-SNAPSHOT.jar`
If you want to run the `ClassicSwitch` code, you have two options:
1. Pass the class to Java: `java --enable-preview -cp "./target/classes" io.tpd.SwitchExpressions`
2. Change the `MANIFEST.MF` file contents to point to `io.tpd.SwitchExpressions`, re-build and execute the jar file again.