Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Java12/Examples"
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
This is an informal page listing examples of features that are implemented by the Java 12 Support. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [https://bugs.eclipse.org/bugs/buglist.cgi?cmdtype=dorem&list_id=18507270&namedcmd=J12.Open&remaction=run&sharer_id=152344 here] | This is an informal page listing examples of features that are implemented by the Java 12 Support. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [https://bugs.eclipse.org/bugs/buglist.cgi?cmdtype=dorem&list_id=18507270&namedcmd=J12.Open&remaction=run&sharer_id=152344 here] | ||
+ | <b>NOTE:</b> | ||
+ | * Switch expression, Enhanced switch statement and Multi-constant case labels are <b>Preview features</b> in Java 12. They are not enabled by default and can by enabled using <b>--enable-preview</b>. | ||
+ | * In Eclipse, <b>--enable-preview</b> can be enabled from the Preferences. It is implicitly added while launching a java program if the feature has been enabled for the project/workspace. | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 55: | Line 56: | ||
<br> | <br> | ||
<br> | <br> | ||
− | [[File:switch- | + | [[File:switch-statement-multi.png]] |
− | | Code compiles (with a preview warning) and while running prints both "Hello" "World" | + | | Code compiles (with a preview warning) and while running prints both "Hello" "World" |
|- | |- | ||
! scope="row" | Positive Compilation 2 (Switch Statement with case with arrow) | ! scope="row" | Positive Compilation 2 (Switch Statement with case with arrow) | ||
Line 76: | Line 77: | ||
<br> | <br> | ||
<br> | <br> | ||
− | [[File:switch- | + | [[File:switch-statement-arrow.png]] |
| Code compiles (with a preview warning) and while running prints only "Hello" (because a break is implicit after every case with an arrow. | | Code compiles (with a preview warning) and while running prints only "Hello" (because a break is implicit after every case with an arrow. | ||
|- | |- | ||
− | ! scope="row" | Positive Compilation | + | ! scope="row" | Positive Compilation (Switch Expression) |
| Use the following code: | | Use the following code: | ||
<source lang="java"> | <source lang="java"> | ||
− | |||
− | |||
public class Test { | public class Test { | ||
Line 109: | Line 108: | ||
| | | | ||
<source lang="java"> | <source lang="java"> | ||
− | |||
− | |||
public class Test { | public class Test { | ||
Line 135: | Line 132: | ||
| | | | ||
<source lang="java"> | <source lang="java"> | ||
− | |||
− | |||
public class Test { | public class Test { | ||
Line 160: | Line 155: | ||
| | | | ||
<source lang="java"> | <source lang="java"> | ||
− | |||
− | |||
public class Test { | public class Test { | ||
Latest revision as of 00:23, 20 March 2019
This is an informal page listing examples of features that are implemented by the Java 12 Support. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry here
NOTE:
- Switch expression, Enhanced switch statement and Multi-constant case labels are Preview features in Java 12. They are not enabled by default and can by enabled using --enable-preview.
- In Eclipse, --enable-preview can be enabled from the Preferences. It is implicitly added while launching a java program if the feature has been enabled for the project/workspace.