• 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

    在这里插入图片描述

    在这里插入图片描述

    正常运行

    在这里插入图片描述

  • 相关阅读:
    ISO14229子类介绍
    C语言实现小游戏之扫雷
    day14--postman接口测试
    SAP CRM 模块:概述,体系结构
    Qt交叉编译到另一台电脑执行报错重新编译
    sql 11
    vue - vue项目使用BOS (百度云对象存储)上传文件
    通过实现HandlerInterceptor接口实现一个拦截器
    数据结构从入门到精通——算法的时间复杂度和空间复杂度
    spark常用的调参详解
  • 原文地址:https://blog.csdn.net/Klhz555/article/details/127730793