// 返回为 true
System.out.println(json == json2);
}
}
- 本地变量类型推断(Local Variable Type Inference)
这一点也是在一些脚本语言中常见的,类似于
必看视频!获取2024年最新Java开发全套学习资料 备注Java
var 表示变量,val 表示常量。
public static void main(String[] args) throws Exception {
//集合
// immutable map build
var map = Map.of(
“cat”, “猫”,
“dog”, “狗”,
“fish”, “鱼”);
// immutable set build
var set = Set.of(“1”, “2”, “3”);
// immutable list build
var list = List.of(1, 2, 3, 4, 5);
// 循环语句
for (var i = 1; i < list.size(); i++) {
System.out.println(i);
}
for (var i : list) {
System.out.println(i);
}
// 异常
try (var in = new ByteArrayInputStream(“123”.getBytes())) {
System.out.println(new String(in.readAllBytes(), “utf-8”));
} catch (Exception e) {
System.out.println(e);
}
// lambda 表达式 意思相同
BiFunction<Integer, Integer, Integer> biFunction = (a, b) -> a + b;
BiFunction<Integer, Integer, Integer> biFunction2 = (var a, var b) -> a + b;
}
- switch
public static void main(String[] args) throws Exception {
var eating = Eating.BREAKFAST;
String eatingZnString = “”;
// 传统写法
switch (eating) {
case BREAKFAST:
case LUNCH:
eatingZnString = “早午饭”;
break;
case DINNER:
eatingZnString = “晚饭”;
break;
default:
throw new Exception();
}
System.out.println(eatingZnString);
// 优化后写法
System.out.println(
switch (eating) {
case BREAKFAST,LUNCH -> “早午饭”;
case DINNER -> “晚饭”;
default -> throw new Exception();
}
);
}
instance of
操作符的模式匹配(Pattern Matching for the instanceof Operator)
interface Animal {}
class Cat implements Animal {
public void mew() {
System.out.println(“喵”);
}
}
class Dog implements Animal {
public void woof() {
System.out.println(“汪”);
}
}
public class Test {
// 传统写法
public static void sounds(Animal animal) {
if (animal instanceof Cat) {
Cat cat = (Cat) animal;
cat.mew();
} else if (animal instanceof Dog) {
Dog dog = (Dog) animal;
dog.woof();
} else {
throw new IllegalArgumentException(“没有这种动物的叫声”);
}
}
// 优化写法
public static void betterSounds(Animal animal) {
if (animal instanceof Cat cat) {
cat.mew();
} else if (animal instanceof Dog dog) {
dog.woof();
} else {
throw new IllegalArgumentException(“没有这种动物的叫声”);
}
}
}
- record 类
// 传统类
public record People(String name, int age) {
public People(String name, int age) {
this.name = name;
this.age = age;
}
public String name() {
return this.name;
}
写在最后
作为一名即将求职的程序员,面对一个可能跟近些年非常不同的 2019 年,你的就业机会和风口会出现在哪里?在这种新环境下,工作应该选择大厂还是小公司?已有几年工作经验的老兵,又应该如何保持和提升自身竞争力,转被动为主动?
就目前大环境来看,跳槽成功的难度比往年高很多。一个明显的感受:今年的面试,无论一面还是二面,都很考验Java程序员的技术功底。
最近我整理了一份复习用的面试题及面试高频的考点题及技术点梳理成一份“Java经典面试问题(含答案解析).pdf和一份网上搜集的“Java程序员面试笔试真题库.pdf”(实际上比预期多花了不少精力),包含分布式架构、高可扩展、高性能、高并发、Jvm性能调优、Spring,MyBatis,Nginx源码分析,Redis,ActiveMQ、Mycat、Netty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!
由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!
Java经典面试问题(含答案解析)
阿里巴巴技术笔试心得
etty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!**
由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!
[外链图片转存中…(img-a0SJQHyf-1716445795164)]
Java经典面试问题(含答案解析)
[外链图片转存中…(img-6xp3U3xw-1716445795165)]
阿里巴巴技术笔试心得
[外链图片转存中…(img-LNi9PPOK-1716445795165)]