![](/img/trans.png)
[英]IntelliJ indicating that enhanced switch block doesn't work despite using Java 14
[英]Java 12 intellij switch expressions doesn't work
我尝试在IntelliJ中使用Java 12,但是当我尝试运行我的应用程序时发生错误
Error:(57, 32) java: switch expressions are a preview feature and are disabled by default.
(use --enable-preview to enable switch expressions)
我添加了应用程序配置VM选项--enable-preview但仍会出现此错误。 我添加了SDK路径。 谁知道我做错了什么?
List<Car> sortedCars = switch (sortType) {
case COLOR -> cars.stream().sorted(Comparator.comparing(Car::getColor)).collect(Collectors.toList());
case MILEAGE -> cars.stream().sorted(Comparator.comparing(Car::getMileage)).collect(Collectors.toList());
case MODEL -> cars.stream().sorted(Comparator.comparing(Car::getModel)).collect(Collectors.toList());
case PRICE -> cars.stream().sorted(Comparator.comparing(Car::getPrice)).collect(Collectors.toList());
};
请确保项目的“项目结构”对话框中的“项目语言级别”设置设置为Java 12.在这种情况下,IntelliJ IDEA将自动添加--enable-preview选项。
运行配置中的VM选项字段会影响应用程序的启动方式,而不会影响其编译方式,因此添加该选项无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.