JAVA使用Switch-case的箭头函数的测试以及yield对属性赋值的测试------JAVA

package com.example.demo;

import org.junit.Test;

public class SwitchTest {
    @Test
    public void Test01(){
        int week = 6;
//        计算结果
        String memo = "";
        switch (week){
            case 1 -> memo = "休息日";
            case 2,3,4,5,6 -> memo = "工作日";
            case 7 -> memo = "星期六";
            default -> throw new RuntimeException("无效的日期");
        }
        System.out.println(memo);
    }
    @Test
    public void Test02(){
        int week = 60;
//        计算结果
        String memo = switch (week){
            case 1 : yield "休息日";
            case 2,3,4,5,6 : yield "工作日";
            case 7 : yield "星期六";
            default : yield "无效的日期";
        };
        System.out.println(memo);
    }
}
package com.example.demo;

import org.junit.Test;

public class SwitchTest {
    @Test
    public void Test01(){
        int week = 6;
//        计算结果
        String memo = "";
        switch (week){
            case 1 -> memo = "休息日";
            case 2,3,4,5,6 -> memo = "工作日";
            case 7 -> memo = "星期六";
            default -> throw new RuntimeException("无效的日期");
        }
        System.out.println(memo);
    }
    @Test
    public void Test02(){
        int week = 60;
//        计算结果
        String memo = switch (week){
            case 1 : yield "休息日";
            case 2,3,4,5,6 : yield "工作日";
            case 7 : yield "星期六";
            default : yield "无效的日期";
        };
        System.out.println(memo);
    }
}

你可能感兴趣的:(JAVA,java,xml,maven,junit,mybatis,json,servlet)