SpringBoot3

发布于:2024-08-25 ⋅ 阅读:(129) ⋅ 点赞:(0)

JDK 关注的新特性

搭建学习环境

有用的新特性

Java Record

看看 Record 怎么用

Instance Methods

静态方法 Static Method

Record 的构造方法

Record Lombok

Record 实现接口

Local Record

嵌套 Record

instanceof 判断 Record 类型

Switch

箭头表达式,新的 case 标签

yeild 返回值

public static void main(String[] args) {
int week = 1;
//yield 是 switch 的返回值, yield 跳出当前 switch 块
String memo = switch (week){
case 1 ->{
System.out.println("week=1 的 表达式部分");
yield "星期日,休息";
}
case 2,3,4,5,6 ->{
System.out.println("week=2,3,4,5,6 的 表达式部分");
yield "工作日";
}
case 7 -> {
System.out.println("week=7 的 表达式部分");
yield "星期六,休息";
}
default -> {
System.out.println("其他语句");
yield "无效日期";
}
};
System.out.println("week = " + memo);
}

Java Record

Text Block

认识文本块

文本块与普通的双引号字符串一样

public void fun1() {
String s1= """
lisi
""";
String s2 = """
lisi
""";
//比较字符串
boolean b1 = s1.equals(s2);
System.out.println("b1 = " + b1);
//使用 == 的比较
boolean b2 = s1 == s2;
System.out.println("b2 = " + b2);
String msg = """
hello world""";
//字符串方法 substring
String sub = msg.substring(0, 5);
System.out.println("sub = " + sub);
}

空白

文本块的方法

转义字符

var

var 声明局部变量

使用时候使用 var

sealed

Sealed Classes

//第一种 final
public final class Circle extends Shape {
}
//第二种 sealed class
public sealed class Square extends Shape permits RoundSquare {
@Override
public void draw() {
System.out.println("=======Square 图形======");
}
}
//密封类的子类的子类
public final class RoundSquare extends Square{
}
//非密封类 , 可以被扩展。放弃密封
public non-sealed class Rectangle extends Shape {
}
//继承非密封类
public class Line extends Rectangle{
}

Sealed Interface

Spring Boot 


网站公告

今日签到

点亮在社区的每一天
去签到