overthemoon
V2EX  ›  Java

java8 以后常用的新特性有哪些?

  •  
  •   overthemoon · Nov 1, 2023 · 5066 views
    This topic created in 1116 days ago, the information mentioned may be changed or developed.

    现在就用到 lambda 函数,还有其它语法吗

    12 replies  •  2024-03-14 14:24:59 +08:00
    wxyrrcj
    wxyrrcj
    Nov 2, 2023
    1
    stream
    JLX
    JLX
    Nov 2, 2023 via Android
    2
    Stream,Optional
    yazinnnn0
    yazinnnn0
    Nov 2, 2023
    3
    密封接口/密封类
    增强 switch 表达式
    record
    record 的各种模式匹配场景下的解构
    lambda 参数名省略类型
    字符文本块
    zgc/分代 zgc
    loom
    结构化并发
    scoped value
    新 ffi
    vector api

    你要说哪个常用, record 及模式匹配, loom 和结构化并发应该会常用
    mmdsun
    mmdsun
    Nov 2, 2023
    4
    其实 lambda + 函数式编程,就有很多东西可以挖掘了。

    比如 lambda 实现其他语言的 closure 闭包函数。甚至模拟 generator 也行。
    ```
    public static void main(String[] args) {
    var count = closure();
    System.out.println(count.get()); // output:1
    System.out.println(count.get()); //output:2
    }

    public static Supplier<Integer> closure() {
    final int[] count = {0};
    return () -> {
    count[0]++;
    return count[0];
    };
    }
    ```
    hello158
    hello158
    Nov 2, 2023
    5
    特性不重要,如果你能找到一个又价值的项目,能让你挣钱,用 Java5 + jsp 写也没问题。
    blacktail
    blacktail
    Nov 2, 2023
    6
    var
    Bromine0x23
    Bromine0x23
    Nov 2, 2023
    7
    var
    jorneyr
    jorneyr
    Nov 2, 2023
    8
    https://openjdk.org/projects/jdk/21/

    修改版本 21 ,逐个查看。
    dif
    dif
    Nov 2, 2023
    9
    var
    stream
    List.of
    CompletableFuture
    lambda (写时一时爽,维护火葬场,尤其是后面跟了一串)
    差不多就这些吧,目前只用到 Java11,没太多变化。
    compiler
    compiler
    Nov 2, 2023
    10
    Kotlin
    hdiwhsg
    hdiwhsg
    Nov 2, 2023
    11
    java8 旧特性。。。
    leee41
    leee41
    Mar 14, 2024
    12
    语法糖上,字符块
    性能上,zgc 和 loom
    实际解决问题常用:结构化并发和 scoped value
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1888 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 10:14 · PVG 18:14 · LAX 02:14 · JFK 05:14
    ♥ Do have faith in what you're doing.