• Eclipse切JRE环境后如何恢复- Unrecognized option: --enable-preview


    场景

    使用switch 新特性 配合 lambda 练习小案例

    // 需求:  1 2 3  ->  一、二、 三
    int num = 1;
    switch ( num) {
        //  jdk13 可以缺省 break   并且 单语句可以省略  花括号   
    	case 1 -> { System.out.println("一"); }
    	case 2 -> System.out.println("二"); 
    	case 3 -> System.out.println("三");
    	default -> System.out.println("未知");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    代码提示 启用 JRE13版本 然后手滑点了一下 导致运行失败

    PS 本机环境是1.8

    The preview feature Case Labels with '->' is only available with source level 13 and above
    
    Change project compliance and JRE to 13 and Enable preview features on project properties
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    在这里插入图片描述

    提示信息

    运行显示错误 – 无法识别的选项:-- 启用预览

    在这里插入图片描述

    Java Virtual Machine Launcher
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    
    Unrecognized option: --enable-preview
    
    • 1
    • 2
    • 3
    • 4
    • 5

    翻译

    • Java虚拟机启动器
    • 错误:无法创建Java虚拟机。
    • 错误:发生致命异常。程序将退出。

    原因

    JDK版本 或者 编译的JRE 环境发生变化

    尝试失败

    按照常规配置依赖方案不得行

    在这里插入图片描述

    右键项目 -> Build Parth -> Add Libraries -> JRE System Libraries -> Libraries  
    
    • 1

    解决方案

    发现因为自己上方的骚操作导致 编译JRE环境 被改变

    右键项目 -> Properties -> Java Compiler 
    
    • 1

    在这里插入图片描述

    上面勾选Use default compliance settings 又提示新的错误

    在这里插入图片描述
    在这里插入图片描述

    发现忘记重新设置版本 下拉勾选 1.8

    在这里插入图片描述

    在这里插入图片描述

    正常运行

    在这里插入图片描述

  • 相关阅读:
    linux中断
    【Scala专栏】方法和函数
    XX攻击——反射型 XSS 攻击劫持用户浏览器
    浅谈App的启动优化
    食品接触材料中的玻璃制品需要做哪些检测认证?
    axios源码分析
    国产+开源:可视化流程引擎助力企业建立流程管理体系
    进程与线程
    胆囊结石的后果
    http发送和接收图片json文件
  • 原文地址:https://blog.csdn.net/Klhz555/article/details/127730793