Java 21 - Language Features and Beyond
Summary
TLDRこのビデオスクリプトでは、Java開発者向けにJDKの最新機能と改善点を紹介しています。Oracleの開発アドボケート、Annaは、Javaの6か月ごとのリリースケイデンスと新機能の利便性を強調し、特にJDK 21以降の簡素化されたメインメソッドやレコードの活用、パターンマッチングの強化について詳述しています。また、Javaの柔軟性と安全性、そして後方互換性を維持しながら、新しい言語機能を試し、フィードバックを提供することでコミュニティに貢献するよう呼びかけています。さらに、実用的な例として贈り物アプリの構築を通じて、Javaの最新言語機能を応用する方法も紹介しています。
Takeaways
- 😀 Javaの新しい機能として、複数のファイルからなるプログラムを実行する機能がJDK 22で追加された。
- 👩💻 Oracleの開発アドボケートとして働くAnnaは、Javaの美しさとクラウドやセキュリティとの組み合わせを楽しんでいる。
- 📈 Javaは6ヶ月ごとにリリースされ、新機能が徐々に追加されている。これはフィードバックを取り入れることでより良い言語機能を提供する。
- 🔍 ValhallaプロジェクトやLoomプロジェクトなどのJavaの進化には時間がかかるが、プレビュー機能を通じてユーザーは安定性と後方互換性を確保しながら新しい機能を試すことができる。
- 📚 Brian GSのアドバイスでは、コードを書くときには言語機能を慎重に選んで、将来の互換性とコードの読みやすさを考慮するよう勧めている。
- 🔑 Javaの新しいメイン関数の構文は、よりシンプルで、void mainを単純なJavaクラスに書くだけで良い。
- 📦 JDK 22では、複数のクラスからなるプログラムを一つのコマンドで実行できるようになった。
- 📝 新しい機能を学ぶ際には、JEP(Java Enhancement Proposals)や関連する記事、動画を参照する。
- 🛠️ Java開発者は、JDK 21以降で提供されているレコード、パターンマッチング、文字列テンプレートなどの新機能を活用して、より簡潔で安全なコードを書くことができる。
- 🔗 dev.java.netやinside.java、JavaチャンネルのYouTubeなどの信頼できる情報源を活用して、Java開発者コミュニティと繋がりながら情報を得ることができる。
Q & A
Java 22の新機能として紹介されたプログラム実行に関する変更とは何ですか?
-Java 22では、複数のファイルからなるプログラムを一度に実行することができる新機能が導入されています。これは、Javaクラスパスに星号(*)を指定して、複数のクラスを含むJavaプログラムを実行する機能です。
AnnaさんはなぜJavaを楽しいと感じていると述べていますか?
-AnnaさんはJavaが美しい言語であると認識しており、12年以上Javaを扱い、Kubernetesやクラウド空間での動きにも興味を持っていると述べています。また、セキュリティと異なるツールを組み合わせてデモや他のアプリケーションを活性化するのも楽しんでいると言っています。
Javaの6ヶ月ごとのリリースケイデンスにはどのような意味がありますか?
-Javaの6ヶ月ごとのリリースケイデンスにより、新しいバージョンがより頻繁に提供され、開発者は新しい言語機能に早くアクセスできます。これにより、開発者は新しい機能を試してフィードバックを提供し、アプリケーションがそれらの機能とどのように連携するかを評価することができます。
ValhallaプロジェクトとLoomプロジェクトとはどのようなものですか?
-ValhallaとLoomはJava言語に新しい機能を追加するプロジェクトです。ValhallaはJavaの性能を向上させるための機能を提供する一方で、Loomは並行性と仮想スレッドを扱うための機能を提供するプロジェクトです。これらのプロジェクトは、開発者がより効率的でスケーラブルなアプリケーションを作成できるように支援することを目的としています。
Brian GSからの引用とはどのようなアドバイスですか?
-Brian GSからの引用は、コードを書くときには慎重に考え、将来もコードを読む人がいることを念頭に置く必要があるというアドバイスです。また、言語機能を選ぶ際には、それらがプロジェクトに有用である理由に基づいて選択する必要があると強調しています。
Java開発者として新しいプロジェクトに参加する際の一般的なプロセスは何ですか?
-新しいJavaプロジェクトに参加する際には、JDKをダウンロードし、IDEを設定し、プロジェクトに必要なビルドツールを用意し、既存のJavaコードを理解することが一般的に求められます。また、プロジェクトの要件に応じてコードを書く必要があります。
jshellツールとは何ですか?どのように役立ちますか?
-jshellはJavaの対話式シェルツールで、開発者が数行のコードを書くだけで迅速に実行し、結果を確認できるように支援します。これはIDEを使わずにコードをテストするのに役立ち、迅速なプロトタイピングに役立ちます。
Java 22での新しいmainメソッドの構文にはどのような変更がありますか?
-Java 22では、新しいmainメソッドの構文として、void main(String[] args)を使わずに、より簡素なvoid main()を使用できるようになりました。これは、Javaクラス内で単純なプログラムを書く際に必要な最小限の構文を提供することを目的としています。
JEP 405とJEP 458とはどのような機能ですか?
-JEP 405は、Javaのレコード機能を簡素化し、クラスとインスタンスメソッドの名前を省略できるようにする機能です。一方、JEP 458は、Javaスクリプトをより簡単に作成できるようにする機能です。これにより、Javaを用いたスクリプト作成が簡略化され、開発者の生産性が向上することが期待されます。
Java 21での文字列テンプレートの変更とは何ですか?
-Java 21では、文字列テンプレートがより柔軟になり、リテラルテキストと埋め込み式の式を組み合わせて特殊な結果を生成することができます。これは、Javaの既存のリテラルとテキストブロックを補完する機能です。
パターンマッチングを使用したswitch式とは何ですか?
-パターンマッチングを使用したswitch式は、JDK 21で導入された機能で、switch式にパターンを含めることができるようになりました。これにより、switch式の表現力が向上し、より安全で簡潔なコードを書くことができます。
変数バインディングのためのパターンと名前付きパターンとは何ですか?
-変数バインディングのためのパターンと名前付きパターンは、JDK 21でプレビューされ、JDK 22で正式に採用された機能です。これにより、switch式において、ケースの左側の変数を右側で使用しない場合に、簡潔にコードを書くことができます。
Outlines
🚀 Java新機能の紹介と開発者へのアドバイス
Oracleの開発者アドボケイト、AnnaはJavaの新機能と開発者へのアドバイスについて語ります。JDK 22では複数のファイルからなるプログラムを実行する機能が追加され、Javaクラスにvoid mainを書くだけで始められます。AnnaはJavaの6か月ごとのリリースケジュールと新機能の小さなチャンスについても触れています。また、ValhallaプロジェクトやLoomプロジェクトの進捗についても言及しています。最後に、Brian GSの言葉を引用し、言語機能を選ぶ際にはコードを書く時間よりもコードを読む時間の方が長いため、言語機能は非常に重要であるとアドバイスしています。
🌱 Java初心者向けの開発環境構築と新機能
AnnaはJava初心者向けに開発環境の構築方法と新機能について説明しています。JDKのダウンロード、IDEの準備、ビルドツールの導入、Javaコードの理解について詳述しています。JShellの使い方やJDK 11からのJavaプログラムの実行方法、JDK 22の新機能である複数のファイルを1つのコマンドで実行する機能についても紹介されています。さらに、Javaの基本概念を理解することの重要性と、JEP 345で提案された簡素化されたメインメソッドの構文についても触れています。
🎁 ギフトアプリケーションのモデル링とJavaのレコード機能
AnnaはJavaのレコード機能を使ってギフトアプリケーションをモデル化する方法を紹介しています。システム要件に基づいてポストカード、クーポン、体験、プレゼントを表現し、それらをレコードとして扱うことでデータの安全性と表現力を高めると説明しています。また、レコードパターンと密封型のインターフェースを使ってシステムの柔軟性と限定性を両立する方法も紹介されています。このセクションではJavaの新しい機能を実際のアプリケーション開発にどのように適用するかが具体的に示されています。
🔍 レコードと文字列テンプレートを使ったデータの扱い
AnnaはJavaのレコードと文字列テンプレートを使ってデータモデルを操作し、JSON形式でデータを送受信する方法について説明しています。レコードの安全性と簡便性、文字列テンプレートによる柔軟な文字列操作、そしてそれらを組み合わせたデータフォーマットの変換方法について詳述しています。JEP 405とJEP 410の機能がどのように役立つか、実際のコード例とともに解説されています。
🔧 パターンマッチングとswitch式の拡張
Java 21でfinalizeされたパターンマッチングとswitch式の拡張についてAnnaが解説しています。switch式にパターンを追加することで表現力と安全性の向上、null値の扱い方、新しいパターンでのswitch式の記述方法について紹介されています。さらに、Java 21でのパターンマッチングの変更点や、enum型の扱い方、exhaustive switchの重要性についても触れています。
🛠 Java開発におけるコードの最適化とメンテナンス性
AnnaはJava 21と22でのパターンマッチングの進化とコードの最適化について話しています。新しいnameとnameパターン変数を使ってコードのメンテナンス性を高める方法について説明し、具体的なコード例を紹介しています。また、dev.java、inside.java、JavaのYouTubeチャンネルなどのリソースを紹介し、開発者コミュニティへの貢献を呼びかけています。
Mindmap
Keywords
💡JDK
💡Java
💡records
💡pattern matching
💡string templates
💡sealed
💡JSON
💡main method
💡JShell
💡cloud space
Highlights
JDK 22 introduces a new feature for running programs supplied as multiple files.
The new 'hello world' in Java can be written with just a void main method in a class.
Anna, a developer advocate at Oracle, discusses the benefits of Java's six-month release cycle.
Java's new features are designed to be tried and given feedback by the community.
Project Valhalla and Loom are mentioned as ongoing Java projects with preview features.
The importance of being thoughtful when choosing language features for coding is emphasized.
JShell is recommended for fast prototyping with Java.
JDK 11 introduced the ability to compile and run Java programs directly from the command line.
JDK 22 allows running Java programs with multiple files using 'java -classpath *'.
JEP 405 proposes simplifying Java for beginners by allowing 'void main' in a class.
The new main method simplifies the traditional 'public static void main(String[] args)'.
The importance of maintaining compatibility for future code evolution is discussed.
Pattern matching for switch expressions in JDK 21 expands expressiveness and safety.
String templates in Java 21 are a preview feature for specialized text processing.
Records in Java provide a safer way to model data and reduce boilerplate code.
Nested record patterns and type inference simplify complex data modeling in Java.
The 'wrap App' example demonstrates using new Java features for a gift-giving application.
The use of sealed interfaces in Java helps limit what classes can extend the interface.
JDK enhancements aim to improve code maintainability and simplify complex operations.
The presentation concludes with an invitation to contribute to dev.java and check inside Java and Java YouTube channel.
Transcripts
coming in jdk
22 is a new feature about running a
program that is supplied as multiple
files so I'm going now in the every of
my records and I'm returning my Json
with my customized content if you're
looking at what's the new main the new
hello world you can see there that you
just need to write a void Main in a Java
class so I had my intention interface
and I made it sealed because I wanted
for the moment to limit what other
classes can extend
it my name is Anna currently working as
a developer advocate in the ja plat from
group team at Oracle I enjoy working
with Java because let's recognize it's a
beautiful language I've been working
with Java for more than 12 years um and
I also love kubernetes and what's
happening in the cloud space I also
enjoy working with security and you know
combining different tools to make my
demos and other applications s to life
and um apart from that well I hope you
will enjoy the demo from today um
speaking of java we've seen this slide
probably many times about the six month
release Cadence of java and you know
that nowadays every six months with
every release of java we get features
well a smaller amount of features like
in the past when we need to wait for
years for that for Java version to be
delivered now we get them faster smaller
chance for us to accommodate with what's
coming new in terms of language features
for also for us to not only just see
what's coming new to try them and give
feedback on them to see like how if our
applications will work with these
features and of course say that to the
community say that to uh the Java
Engineers that hey this probably doesn't
cover my use case and that to be taken
into consideration
and of course when we talk about these
features many of them fall in the
chunks in these projects there's just a
bunch of just a small portion of the jav
projects that have been enrolled in the
past years uh not all projects get
updates of
course um and well sometimes people
already ask about what's going on with
Valhalla when we're going to get
Valhalla there's always this question um
for Loom again there was a a little
weit uh but all these wait and see of
preview features incubator features and
so on until the features are made final
is for us all of us to take advantage of
the stability of java of having also the
backwards compatibility have the safety
in it and have all the cases all of us
being covered by
it um and this slide doesn't have some
other projects but uh they also make our
lives better as
well
so I want to start this talk uh with a
few with a nice quote from Brian GS from
his talk in
Belgium uh but this is a very good
advice also for yourself when you're
picking language features in your
projects as well the reason well one
first thing that you can think about
when we're writing code well let's face
it we spend little time writing code we
spend more time thinking about what
we're going to write but we also spend a
lot of time reading that code so
language features mean a lot for us
because I mean for the future we and our
colleagues are going to read that code
and of course we need a thoughtful way
to move
forward um again when we're coding we
also need to think about how that piece
of code that we're writing is going to
evolve in the future and moreover not
only how it's going to evolve in the
future but what's it compatibility with
with other plans of
Integrations and well there is another
catch to this quote that I'm going to
share a little later but just keep it in
mind to be thoughtful when you're
choosing features and language features
when you're coding just don't pick them
because they're beautiful but they're
because they're useful to your
project so let's
start I want to ask you something um can
you please raise your hand if in the
audience are any Junior Jaa developers
if you consider yourselves Junior Java
developers so we have one
two okay you can okay it's all about how
you consider yourself so we have three
uh Juniors that's great
welcome um how many of you think of
themselves like having medium Java
knowledge okay that's surprising from
some people good you see like kind of
half room and senior experts in Java you
know everything one two please don't be
shy come
on let's say equal to the menu um so as
the seniors we're used to writing code
um after let's say 12 years of java
feels natural to write code it just
flows right um and we know how to write
code we we know how to test it all
becoming very let's say automatic and
normalized to us however those that are
about to start with the
language they feel it
differently um
because when you join a new Java project
that's something that I always related
in the past whenever I was joining a new
project it was always like this well
let's say the ID was there before but
they were always telling me okay install
the jdk x that the project is using then
this is the project setup which was
usually cumbersome related in some areas
with the infrastructure and so on and uh
well this is Java code and most of the
Java projects that have maturity that
reach production back in the day when I
started they had a lot of
code uh which is good because mature
projects usually have a lot of code
however if we're looking at this piece
of code my some say that's not that much
but we just have a simple hello world so
from operational point of view I would
say that you need for starting with Java
download the jdk have an ID uh make sure
that you are having a build tool because
well we're working on real life projects
and those are using a build tool and of
course the Java code that uh if you're a
junior that probably others have have
coded on or if you're just joining the
project others have coded on so in order
to enhance the usability of working with
Java there have been uh put there have
been out there some tools to help and
make our life nicer it comes to fast
prototyping with Java one of them being
jshell and totally recommend it uh to
just if you want to write a few lines of
code and see if it works and just not go
to the ID make a new Java file and try
everything just go nicely to the command
line jshell and just drop it
there um secondly since jdk 11 you can
just say Java your hello world Java or
however your name your file is called
and that is being compiled and run for
you and you get the hello world so no
more Java C first and then Java and all
this
ceremony and coming in jdk
22 is a new feature about running Java
programs multi running a program that is
supplied as multiple files in just one
go with Java minus class path star there
and of course hello world Java so if
hello world Java is provided as two
files you can grun it nicely like this
uh if you're trying by the way the jdk
22 Early Access build it can already
Works um so it's pretty cool and
simplified way of running Java
right but
still uh let's talk about beginning with
Java the beginning still looks like this
right so we need to know some Concepts
if we want to write the hello world job
the hello world here right we need to
know about um access modifiers we need
to know about what's that a class what's
that a method why can't I put methods
outside classes so you need to know all
the ceremony of
building just five lines of code you
need to know all the ceremony of java to
write uh more complex things to know
what are the what's the static versus
instance Behavior what are parameters
what are return types and so on so in
order to help the people that are just
learning
Java there's a new there's a Jeb Jeb
445 that thinks on how to simplify
things for those that are learning Java
but not only so and name classes and
instance main methods is a preview uh
feature in 21 gets its second preview in
22 by the way um and well
if you're looking at what's the new main
the new hello world you can see there
that you just need to write a void Main
in a Java class and you system out print
line the hello world and that's it now
this is not just the idea of
eliminating U you know make a shorter
syntax right it's not about shorter
syntax it's about the fact that this
simple program should actually contain
the minimum that you need to write it
right you don't you don't need the
string arguments since you're not you
know processing that further in your
program um and to be to be honest when
whenever we have a new idea and whenever
want to try something we always start
with simple methods we build up classes
and inheritance and everything else at a
at a bigger rate we're not just thinking
of everything out of the box just from
the
beginning but this is also useful for us
in general for writing scripts in Java
so think of that as well it's not just J
Junior developers that are helped but us
as well when writing scripts in
Java and I promise you the second part
of the quote so here's the second part
of the
quote like don't do today um things
don't do things today that you don't
want to be compatible with tomorrow now
this is some of you might say okay this
is easy to
say um it's always tough whenever when
there's pressure on you
uh to uh deliver and to put things in
action however always think of tomorrow
and the people that are going to come
after you how are we going to work with
that piece of
code and in the context of this job
there might be the question like okay so
this is the new main however what if my
program has two types of main because
that one was the most simple way to
write the void M but maybe there are
other ways that I can you know
truncate the old syntax so there's an
invocation order with the Syntax for the
new main so for example the traditional
public static void main string ARS will
have precedence if it's used in a Java
class um next if you're having one
static void main without the string arcs
that's going to be evaluated
second uh the third evaluation comes for
avoid main string arcs so no static
modifier there and last but not least
the one that you saw earlier in my Slide
the very very very very simplified
version of void main please pay
attention that all these are not private
so don't make it private then it's not
going to work so this is um a simplify
way um nice language gift to start
simpler with Java if you want to know
more on this feature you can know more
this feature uh by reading the two chps
of course um there there's a very nice
video done by my colleague Nikolai on
how to script Java easily in 21 and
Beyond and of course Java 22 unpacking
that contains more about this feature
but also about the other one that I
mentioned the jet
458 okay so now we talk about Beginnings
but we'll write most of the time uh Java
programs that contain business logic
right so let's go to something me with
more
meet so most of the time our developer
Works requires to model the business
logic of our software right there's
always requirements coming to us from
business uh Sim formulated in a uh I
don't know more generic or more
specified more specific uh
manner so with that in mind let me bring
to your attention a small application
that I built for the jvm advant
calendar so this is called the wrap App
application
and is uh sending gifts so the idea is
pretty simple and the reason why I put
the QR there is for you to scan it
because we're going to use these
requirements throughout the application
so it's better like to have them on
mobile if you want to refresh on the
requirements since they're new so a
center can do a nice gesture and send
somebody a very nice gift right and a
center can choose to send a nice
postcard or or is very important a
surprise depending on celebration and
the surprise can be of different types
it can be a coupon an experience I don't
know like jumping with parachute or a
present a physical present now a
postcard does not have an Associated
cost but all the other ones they
do um and an online coupon has an expiry
date while the others
they don't a present can be placed
inside a box which can have a cost as
well and of course a sender can never
give two postcards as a gift the system
will pick up the first postcard and ship
it to the receiver so these are some
let's say minimal requirements for an
application an imagined application we
not I didn't use any framework for it
now in real life probably you're going
to pick a good framework to make this a
reality but I just wanted to use a few
simple language features just to you
know prototype it fast prototype it so
first
thing I thought about my model and I was
thinking like okay how I'm going to
model this and I thought about what I
have in my system so I have postcards I
have surprises which can be of three
types uh well all of them while
postcards don't have a price the others
have a price so
whenever a Senter wants to send some of
these to a
receiver this feels like data and I need
something to carry my data throughout my
system but if I'm sending this request
let's say to the system as Json I don't
want to process Json and strings
throughout all my system I want to make
it into a model that's more closer to me
so I thought of using records for
postcard for example for just to start
off and not just because well they're
nice and they reduce boilet plate and uh
they're a new cool feature but it also
because well they're safer this
realization um proceeding in records
through the Constructor preventing
forging of instances so that's one first
design choice that I took
secondly I thought about use more of the
versatility of records and use record
patterns because if some of you have
been to the talk about the Java language
Futures well they fuse a type test with
conditionally uh a type test with
conditionally extracting the record
components so what you're seeing here
you can see that I can deconstruct a
record into its
components in a more easier way compared
to Java
16 and of
course I can do it like this but I can
also use type inference for buying dat
binding two record components
so let's look again at our system our
system like this the class diagram that
resulted from
it um and having in mind the
requirements that we initially had uh I
thought okay so postcard coupon and
experience and and present they're all
good intentions from someone so I had my
intention
interface and I made it sealed because I
wanted for the moment to
limit what other classes can extend it
and at the moment all I know from my
business is that only these four types
are permitted by my system I'll deal
with the rest later so I'll make this
sealed uh
secondly I need to think about modeling
so I said already that postcard is a
record but besides that coupon
experience and present are also
records and last one gift because gifts
can be either
postcard or one coupon or one experience
or one present so it feels like it's
something nested there so gift was
represented using nested record patterns
and this is well composing pattern
because while records are not just for
representing simple like for
representing the simple data like we saw
earlier with postard but they also can
be composed with nesting and it's more
natural to my system to describe my
system
thirdly if I'm looking again to working
with the nested record
patterns um as of java
21 I can deconstruct I said earlier the
record into its components so gift is it
can be a postcard or an experience I can
check it always and have the instance
off against that but as I said earlier I
can go even a little
deeper and if for example I need access
to the currency I can do that directly
without looking and saying hey gift give
me the postcard give so give me the
experience give me the
currency and of course last but not
least use type INF ference for binding
to record components so for example
since I'm just using uh the currency
here I'm not interested in representing
the type of the rest of the record
components and I just used
VAR so we have one stage for Ming our
system if you want to know more here
here are some useful links and the je W
440 which by the way this feature is
final so safe to kind think of it safe
to use in production but it's final use
it enjoy using
it um another feature that came with
Java 21 it was very much discussed was
about string templates so string
templates were thought to complement
Java's existing literals and text blocks
probably use text blocks so far but what
they have special is that they couple a
literal text with embedded expressions
and template processors to produce
specialized results this is a preview
feature and as I said earlier from my
sender I get a Json right I'm
transforming that into something that's
okay for my system that I can work with
it's I make my new model but I need to
send my model back I need to format the
gift back right so maybe string
templates can help me to format again to
string I can use this it's a way so I
can use a simple string template the SD
that's given by by the
jdk and just use the simple template
processor the dot and of course the
template where I can embed
Expressions but I can also produce
specialized
format by using the template processor
API and making my temp template to
process strings but return gson right so
you can always use the string template
processor off to make a processing to
process a string and of course return
the
Json uh and the first time that I
implemented this and a simple way to
implement this for Json is like in the
slide so I'm just hanging the string
template processor of string template
and then I'm just returning a new Json
object so we have now this in the our
interface and of course the method as
Json for each of our records so I'm
going now in the every of my records and
I'm just you know validating my J I'm
returning my Json with my customized
content and I can also Place expressions
like the turn your operator to calculate
the price that can happen as well in
this in the templates I just don't need
to calculate that beforehand to put it
there so pretty much simplified looks
like this and it's all very clean and
nice so if you want to know more there's
a newscast about how to interplate
strings in Java 21 uh more on uh string
templates in the jeps themselves there's
getting a new there's a new a second
preview in
jk22 and of course there is an article
on inside Java with the code that I
showed you earlier and more around
it but let's model a little further our
system so now we know that our system
has records is processing Json can
return Json further but we need
operations right so in order to have
clean
operations we're going to use pattern
matching for switch um feature that was
finalized also on jdk 21 je
441 and has many
flavors
so this one this feature was to made to
expand the expressiveness and of the
switch expressions and allowing them to
have patterns in the case
labels uh of course they can also treat
the null hosti that we know about like
you can have null in a case that's what
we know for the switches of course
secondly well they increase the safety
of switch
statements by requiring the pattern
switch statements to cover all possible
input
values and last but not least as always
very important for Java backwards
compatibility so your previous switches
are also safe to use they didn't affect
that uh what's new with jdk 21 I don't
want to cover all the changes that
happen with pattern matching so with jdk
21 there were no more parenthesized
patterns and you can use qualified inum
constants in case uh La in uh case
labels so what this means is that like
for example a postcard can have fonts
right and let's say font
there are also two types they can you
can have color and you can have weight
for the font it can be bold uh stra it
can be bold italic or
regular uh and you want to treat those
cases differently PR prior to jdk 21 you
couldn't achieve the cases with W on
enams now you can do this and elegantly
and nice so these were the what the the
changes that occurred uh for um pattern
matching and switch only for
21 but this is just for the processing
of the color I said we need more
operations so if I am to think again to
my requirements for processing the
request and returning the gifts based on
what the system was requiring a possible
modeling of the system is to have an
exhaustive switch that treats all the
cases for my system yeah there're a lot
but this you what you get um and you
need to check of course for some edge
cases when maybe somebody says Okay I
want everything for free um and you need
to say hey if you want for free you're
just getting a postcard you know you
don't trick the system um but for the
other cases where you're wanting to send
a postcard and a gift or or another
surprise to someone you can just merge
the two and happen there so this is the
first date of the switch a lot of
options and I think some of you already
see some way to optimize this and that's
very
good um so let's optimize this if you
want to know more for the moment about
pattern matching I can recommend you to
of course read the Jeb but moreover
there are some uh nice writing from
Brian GS about uh pattern matching in
the Java object model and pattern
patterns exhausted inconditional and
reminder and of course the state of
pattern matching from 2022 of
Brian's so we want to let's say improve
the last Improvement to give to our code
because there were some things that were
overlapping but that's very um very easy
to do thanks to another uh preview in
jdk 21 but becoming Final in jdk 22 and
name and name patterns and variables to
improve code mainten ability somebody
these already might suggest that to you
by the
way this um Fe Fe comes in the context
for the fact that is common for programs
to just need only some of the components
for further processing like we saw
earlier right so for example the code we
had earlier if we are to look at it can
become this the reason being is because
on the right side of the each case we
don't always use everything that's on
the left in the case so for example in
case case of the gifts we can easily
replace with underscore the ports that
we're not using further right so this
switch earlier gets simplified to less
cases to treat and everything gets put
together in this short
sentence
um so it's great that's finalizing jdk
22 but I suggest we give it a try
starting with
21 as it would be F to give some time
for others as
well I would like to tell you to stay
tuned for more to go and check the
articles on dev. Java and to invite you
to contribute to dev. Java as we welcome
Community contributions from you to in
writing better articles to help
developers improve
themselves uh I welcome you to also
check inside Java where we publish it's
like an aggregate of news what's going
on with the latest Chups that are
published for each new jdk release but
also can be like examples or research by
some J uh by some jdk engineers and all
is aggregated by date author and tag tag
is very useful because for example if
you need any everything that has ever
been aggregated there in garbage
collection you get a lot of learning on
garbage collection so and of course as a
trusted source as those people that are
contributing there they really TR try to
do their best to to write uh helpful
content but not only that but they are
the experts in Java that right there and
last but not least the youtube.com Java
if you enjoy videos and uh yeah there
we're trying to make a video
format of the written part that is most
of the time on dev. Java or inside. Java
that was it from my side I want to
welcome some questions these are the
slides and there's the code so enjoy The
Code by the way has a little bit more
complexity but because it has some other
cases treated but you're going to see
most of it matching
the what I showed you in the slides here
so if any our questions are there
welcoming them all
clear okay thank
[Applause]
you
Browse More Related Video
![](https://i.ytimg.com/vi/O_bmmDWIjTc/hq720.jpg)
OpenAIのGPTsより凄い!無料で使えるDifyを徹底解説してみた
![](https://i.ytimg.com/vi/v2x24L33yHk/hq720.jpg)
【神アプデ】マメ愛用のブラウザアプリ『Arc Search』の新機能が気になり過ぎるぞ...。
![](https://i.ytimg.com/vi/jA7xwOsFffU/hq720.jpg?sqp=-oaymwEmCIAKENAF8quKqQMa8AEB-AH-CYAC0AWKAgwIABABGBMgSCh_MA8=&rs=AOn4CLCVKUE2CNadOJpPRAVc_JndGI-GTg)
How will AI transform precision medicine? – Ava Amini
![](https://i.ytimg.com/vi/eUEe40M9JK8/hq720.jpg)
AI News: AGI In 2 Years, Meta’s LEAK, AI Sarcasm Detector & More
![](https://i.ytimg.com/vi/ukwsTjU6tPY/hq720.jpg)
NEW Copilot in Azure AI Studio *2024*
![](https://i.ytimg.com/vi/CdQd6rfIv5M/hq720.jpg)
Dify AI: Create LLM Apps In SECONDS with NO Code FOR FREE! Flowise 2.0?
5.0 / 5 (0 votes)