Quantcast
Viewing all articles
Browse latest Browse all 2045

มาดู feature ที่น่าสนใจใน Java 21 GA ที่เพิ่งปล่อยออกมา

Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

Java 21 GA นั้นเพิ่งปล่อยออกมานั้น
มี JEPs ออกมา 15 ตัว พร้อมกับแก้ไข bug ไปมากกว่า 2,000 ตัว
โดย feature มีดังนี้

  • Vector API (Sixth Incubator)
  • String Templates (Preview)
  • Unnamed Patterns and Variables (Preview)
  • Unnamed Classes and Instance Main Methods (Preview)
  • Scoped Values (Preview)
  • Foreign Function & Memory API (Third Preview)
  • Structured Concurrency (Preview)

มาดูตัวที่น่าจะได้ใช้กัน

Record Patterns – JEP 440

เพิ่มเข้ามาตั้งแต่ Java 19 แล้ว
สามารถทำงานร่วมกัย instanceof และ switch-case ได้

[gist id="03566c6bd11252b5fe086af2962b78fb" file="1.java"]

String Templates (Preview)

[gist id="03566c6bd11252b5fe086af2962b78fb" file="2.java"]

Unnamed Patterns and Variables (Preview)

[gist id="03566c6bd11252b5fe086af2962b78fb" file="3.java"]

Structured Concurrency (Preview)

สำหรับ concurrent program ใน thread ต่าง ๆ ตัวอย่างเช่น

[gist id="03566c6bd11252b5fe086af2962b78fb" file="4.java"]

Unnamed Classes and Instance Main Methods (Preview)

[gist id="03566c6bd11252b5fe086af2962b78fb" file="5.java"]

พร้อม upgrade Java 21 กันหรือยัง

Reference Websites


Viewing all articles
Browse latest Browse all 2045

Trending Articles