用Maven编译并执行JDK预览功能

问题描述 投票:22回答:1

使用JDK/12 EarlyAccess Build 10,JEP-325开关表达式已集成为JDK中的预览功能。表达式的示例代码(同样在JEP中):

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 -> System.out.println("Enjoy the holiday!");
}

其中Day为枚举,>]

public enum Day {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

Preview Language and VM Features JEP-12已经详细说明了如何在编译和运行时使用javacjava启用功能。

如何使用Maven尝试此功能?

在JDK / 12 EarlyAccess Build 10中,JEP-325开关表达式已集成为JDK的预览功能。表达式的示例代码(同样在JEP中):扫描程序扫描程序=新...

java maven switch-statement java-12 preview-feature
1个回答
26
投票

步骤1

© www.soinside.com 2019 - 2024. All rights reserved.