JDK13的新特性

2024-04-22

switch

引入yield关键字,用于返回指定的数据,结束switch结构
意味着switch表达式使用yield返回值,使用break不返回值
yield只会跳出当前switch,return会跳出当前方法
int day = 0;
int result = switch (day) {
	case 1 -> {
		yield 1;
	}
	case 2,3,4 :
		yield -1;
	default -> {
		yield 0;
	}
};

文本块

JDK13预览特性,JDK15转正
"""
"""
会保留换行
public void test() {
	String info = """
	dasda
	asdad
	dsada
	""";
}


{/if}