Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Java13/Examples"
(5 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | |||
This is an informal page listing examples of features that are implemented by the Java 13 Support. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [http://eclip.se/fP here] | This is an informal page listing examples of features that are implemented by the Java 13 Support. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [http://eclip.se/fP here] | ||
<b>NOTE:</b> | <b>NOTE:</b> | ||
* Switch expression, Enhanced switch statement and Multi-constant case labels are <b>Preview features</b> in Java 13. They are not enabled by default and can by enabled using <b>--enable-preview</b>. | * Switch expression, Enhanced switch statement and Multi-constant case labels are <b>Preview features</b> in Java 13. They are not enabled by default and can by enabled using <b>--enable-preview</b>. | ||
+ | * TextBlock is also another preview feature in Java 13. | ||
* 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. | * 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. | ||
Line 38: | Line 38: | ||
A checkbox to enable preview features is available on the preference page. | A checkbox to enable preview features is available on the preference page. | ||
|- | |- | ||
− | ! colspan="3" | | + | ! colspan="3" | Preview Feature: Switch Expressions, Enhanced Switch Statement and Multi-Label Case Statements. |
|- | |- | ||
! scope="row" | Positive Compilation 1 (Switch Statement with multi-label case with colon) | ! scope="row" | Positive Compilation 1 (Switch Statement with multi-label case with colon) | ||
Line 117: | Line 117: | ||
public String getDay_1 (Day today) { | public String getDay_1 (Day today) { | ||
String day = switch(today) { | String day = switch(today) { | ||
− | case MON, TUE, WED, THUR, FRI | + | case MON, TUE, WED, THUR, FRI-> "Weekday"; |
− | case SAT, SUN | + | case SAT, SUN->"Weekend"; |
}; | }; | ||
return day; | return day; | ||
Line 174: | Line 174: | ||
[[File:switch.cover-all-cases.error.yield.png]] | [[File:switch.cover-all-cases.error.yield.png]] | ||
| Compiler error is shown | | Compiler error is shown | ||
+ | |- | ||
+ | ! colspan="3" | Preview Feature: Text Blocks | ||
+ | |- | ||
+ | ! scope="row" | Text Block Example | ||
+ | | Compile and run the following code: | ||
+ | <source lang="java"> | ||
+ | @SuppressWarnings("preview") | ||
+ | public class Test { | ||
+ | public static void main(String[] args) { | ||
+ | String tb = """ | ||
+ | Hello | ||
+ | World | ||
+ | """; | ||
+ | System.out.println(tb); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br> | ||
+ | <br> | ||
+ | [[File:textblock.png]] | ||
+ | | Code compiles prints both "Hello" "World" as it is - notice that "World" is printed in the next line. | ||
+ | |- | ||
+ | ! scope="row" | Text Block Compilation Error Example | ||
+ | | Use the following code: | ||
+ | <source lang="java"> | ||
+ | public class Test { | ||
+ | public static void main(String[] args) { | ||
+ | String tb = """ | ||
+ | Hello | ||
+ | World | ||
+ | ""; | ||
+ | } | ||
+ | }</source> | ||
+ | |||
+ | <br> | ||
+ | <br> | ||
+ | [[File:textblock.error.png]] | ||
+ | |Compilation error - text block not closed properly | ||
|- | |- |
Latest revision as of 00:21, 16 September 2019
This is an informal page listing examples of features that are implemented by the Java 13 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 13. They are not enabled by default and can by enabled using --enable-preview.
- TextBlock is also another preview feature in Java 13.
- 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.