preview-feature

Java records with nullable components

大兔子大兔子 提交于 2021-02-04 15:39:07
问题 I really like the addition of records in Java 14, at least as a preview feature, as it helps to reduce my need to use lombok for simple, immutable "data holders". But I'm having an issue with the implementation of nullable components. I'm trying to avoid returning null in my codebase to indicate that a value might not be present. Therefore I currently often use something like the following pattern with lombok. @Value public class MyClass { String id; @Nullable String value; Optional<String>

Maven Exec Plugin with Preview Features

蓝咒 提交于 2020-06-13 07:57:18
问题 It's easy to compile your Java sources with --enable-preview : <!-- Enable preview features --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>15</release> <compilerArgs>--enable-preview</compilerArgs> </configuration> </plugin> But how can you then run exec:java ? Using <!-- Exec plugin.. run with `mvn exec:java` --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven

Maven Exec Plugin with Preview Features

故事扮演 提交于 2020-06-13 07:57:14
问题 It's easy to compile your Java sources with --enable-preview : <!-- Enable preview features --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>15</release> <compilerArgs>--enable-preview</compilerArgs> </configuration> </plugin> But how can you then run exec:java ? Using <!-- Exec plugin.. run with `mvn exec:java` --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven

how to set the use --enable-preview compile and run flags from gradle?

狂风中的少年 提交于 2020-06-12 09:24:06
问题 Looking to use records from Java 14 in a gradle build, but am getting: thufir@dur:~/NetBeansProjects/FileWatcherHandler$ thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build > Task :compileJava FAILED /home/thufir/NetBeansProjects/FileWatcherHandler/src/main/java/net/bounceme/dur/files/FXOrder.java:3: error: records are a preview feature and are disabled by default. public record FXOrder(int units) {} ^ (use --enable-preview to enable records) 1 error FAILURE: Build failed

how to set the use --enable-preview compile and run flags from gradle?

北城以北 提交于 2020-06-12 09:24:03
问题 Looking to use records from Java 14 in a gradle build, but am getting: thufir@dur:~/NetBeansProjects/FileWatcherHandler$ thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build > Task :compileJava FAILED /home/thufir/NetBeansProjects/FileWatcherHandler/src/main/java/net/bounceme/dur/files/FXOrder.java:3: error: records are a preview feature and are disabled by default. public record FXOrder(int units) {} ^ (use --enable-preview to enable records) 1 error FAILURE: Build failed

Pattern matching instanceof [closed]

混江龙づ霸主 提交于 2020-05-23 06:50:27
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 hours ago . I came across this amazing topic on https://www.baeldung.com/java-pattern-matching-instanceof. But when I try to run the following code, it throws compile time error: if(obj instanceof String s) { System.out.println(s); } I am using Java 14. 回答1: This is a preview feature in Java 14, see JEP 305 and

Pattern matching instanceof [closed]

半腔热情 提交于 2020-05-23 06:50:07
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 hours ago . I came across this amazing topic on https://www.baeldung.com/java-pattern-matching-instanceof. But when I try to run the following code, it throws compile time error: if(obj instanceof String s) { System.out.println(s); } I am using Java 14. 回答1: This is a preview feature in Java 14, see JEP 305 and

Compile and execute a JDK preview feature with Maven

吃可爱长大的小学妹 提交于 2019-12-28 02:07:12
问题 With JDK/12 EarlyAccess Build 10, the JEP-325 Switch Expressions has been integrated as a preview feature in the JDK. A sample code for the expressions (as in the JEP as well): Scanner scanner = new Scanner(System.in); Day day = Day.valueOf(scanner.next()); switch (day) { case MONDAY, TUESDAY -> System.out.println("Back to work.") ; case WEDNESDAY -> System.out.println("Wait for the end of week...") ; case THURSDAY,FRIDAY -> System.out.println("Plan for the weekend?"); case SATURDAY, SUNDAY -

Error:java: error: invalid source release: 13 using JDK12 with IntelliJ

浪尽此生 提交于 2019-12-07 06:58:24
问题 I am trying to build a project with JDK-12 ea. While trying to execute a sample class: public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int value = scanner.nextInt(); // After JEP-325 switch (value) { case 1 ->System.out.println("one"); case 2 ->System.out.println("two"); default ->System.out.println("many"); } } The IDE throws the error that reads Error:java: error: invalid source release: 13 Relevant project configuration screens : Module settings SDKs

Error:java: error: invalid source release: 13 using JDK12 with IntelliJ

怎甘沉沦 提交于 2019-12-05 12:17:26
I am trying to build a project with JDK-12 ea. While trying to execute a sample class: public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int value = scanner.nextInt(); // After JEP-325 switch (value) { case 1 ->System.out.println("one"); case 2 ->System.out.println("two"); default ->System.out.println("many"); } } The IDE throws the error that reads Error:java: error: invalid source release: 13 Relevant project configuration screens : Module settings SDKs Compiler settings About IDE: IntelliJ IDEA 2018.3.3 (Community Edition) Build #IC-183.5153.38, built on