No video

Clean Code with Records, Sealed Classes and Pattern Matching by José Paumard

  Рет қаралды 24,176

Devoxx

Devoxx

Күн бұрын

The releases of the JDK 17 to 19 bring interesting features in the Java language: sealed types, pattern matching for switch (as a preview feature). Along with the introduction of records, the implementation of pattern matching in the Java language begins to take shape. The JDK 19 brings even more with Record pattern matching (as a preview feature), that further simplifies your code. In this presentation we show you how records are working, how you can use them to make your code much more readable, and how you can leverage sealed types and switch expressions to improve the modularity of your application. You will see pattern matching in action on real examples, how it will change the way you write Java code, and what you can expect on this topic in the future. It is mostly a live coding presentation, with some slides when the code shown cannot be executed.
JOSÉ PAUMARD
José works as Java Developer Advocate at Oracle. PhD in applied maths and computer science, assistant professor at the University Sorbonne Paris Nord for 25 years, he is a Java Champion Alumni and JavaOne Rockstar. He is a member of the french Paris Java User Group, has been a co-organizer of the conference Devoxx France, and is a disorganizer of JChateau, an unconference held in the Chateau of the Loire Valley. He works on the dev.java documentation and community website, publishes the JEP Café, a monthly video cast on KZfaq, and maintains a french KZfaq channel with more than 80 hours of Java courses. He is also a Pluralsight author in the Java space.
------------------------------------------------------------
INTRO
* visuals & editing by @Mercator
* music : Avocado by Ephixa

Пікірлер: 20
@AyushmanAdhikary
@AyushmanAdhikary 13 күн бұрын
Very informative. Always enjoy your content which is conceptually so clear to understand.
@MrGabblit
@MrGabblit Жыл бұрын
Very insightful, well presented talk
@francksgenlecroyant
@francksgenlecroyant 10 ай бұрын
I think the serialization process is using the Constructor even with regular java classes, the reason why the validation rule is not triggered is because, the constructor which is involved here is the default non-args constructor. That's it!
@khalled95
@khalled95 Жыл бұрын
The main issues in java 17 that companies don't use or upgrade to it, most companies stick with java 8 or 11
@PietervandenHombergh
@PietervandenHombergh Жыл бұрын
Coverage in the switch can be achieved with an anon innner of the Shape in a unit test.
@PanMaciek
@PanMaciek Жыл бұрын
I love using pattern matching, but seeing how java is going to implement this I'm not sure it will feel great
@GavinFreeborn
@GavinFreeborn Жыл бұрын
This summarizes every functional feature java has added. Kinda sad but I guess it's at least there. Unfortunately a poor implementation means it's much harder to sell at work
@TaranovskiAlex
@TaranovskiAlex Жыл бұрын
Thank you for the great talk!
@DavidBeaumont
@DavidBeaumont Жыл бұрын
I have a question about pattern matching on records (about 35:00). If you use "(Circle radius) -> radius * radius", what happens if you add a new component to Circle (e.g. a colour)? Now the record has a new canonical constructor. And worse, what if the property is the same type as the existing value (e.g. "double celcius"). Now I think that all the callers using pattern matching must update their code with a '_'? I guess (looking ahead) the owner of the type would be responsible for adding an explicit custom pattern to retain the old semantics, but this would be a manual thing you need to remember to do.
@jamesschmames6416
@jamesschmames6416 Жыл бұрын
I thought it was bad form to throw exceptions in a constructor.
@patrickproctor3462
@patrickproctor3462 Жыл бұрын
It should be done judiciously. We use exception throws in constructors for user-provided data so we fail very loudly, very clearly, and in a way that tells our UI developers (and others) that they broke the rules of our API (without resorting to WSDLs which NO ONE wants to maintain).
@OMGitzBadCompany
@OMGitzBadCompany Жыл бұрын
It's far better than knowingly letting invalid objects pop into existence.
@IFraid
@IFraid Жыл бұрын
So, basically c#
@rsrini7
@rsrini7 Жыл бұрын
java becomes another scala
@pierre-jeanmartin5621
@pierre-jeanmartin5621 Жыл бұрын
They should have picked a new language keyword instead of “instanceof”. Something like “ofpattern”. if ( object ofpattern Point(int x, int, y) ) // use x and y Or maybe it’s just me very not liking instanceof 😅
@DavidBeaumont
@DavidBeaumont Жыл бұрын
Adding new keywords is very hard since it's adding a new reserved word to the language specification and might make existing code stop compiling (e.g. if I have a variable or type called "ofpattern". I agree that "instanceof" is a bit unintuitive though, but it might be the pragmatic choice.
@pierre-jeanmartin5621
@pierre-jeanmartin5621 Жыл бұрын
@@DavidBeaumont i understand but it’s not like all modern IDE have a Replace in Files feature. A simple name like record was introduced but a non camel case keyword like « ofpattern » would be a problem 🤨🤔
@DavidBeaumont
@DavidBeaumont Жыл бұрын
@@pierre-jeanmartin5621 what about tools which process Java files or databases containing symbol information of binaries for debugging. There are a lot of potential ways new keywords can mess things up in hard to fix ways. Record is, I think, much easier because it's a new type identifier rather than a language keyword.
@MrKar18
@MrKar18 Жыл бұрын
​@@pierre-jeanmartin5621what about 10000 if libraries using? You can't modify existing libraries. Java has always been backward compatible. It can't be make or break as its enterprise's go to language.
@KangoV
@KangoV 6 ай бұрын
maybe if(object match Point(var x, var y)); ?
Teaching old Streams new tricks  By Viktor Klang
50:51
Devoxx
Рет қаралды 20 М.
娜美这是在浪费食物 #路飞#海贼王
00:20
路飞与唐舞桐
Рет қаралды 4,8 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 36 МЛН
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 17 МЛН
English or Spanish 🤣
00:16
GL Show
Рет қаралды 8 МЛН
Know your Java? by Venkat Subramaniam
37:41
Devoxx
Рет қаралды 16 М.
Let’s Set the Records Straight
53:06
IntelliJ IDEA, a JetBrains IDE
Рет қаралды 7 М.
Stop Recommending Clean Code
27:05
ThePrimeTime
Рет қаралды 476 М.
Deep Dive with Java Records with Jason Young
29:39
SpringDeveloper
Рет қаралды 10 М.
Revisiting Design Patterns after 20 by Edson Yanaga
48:24
Java Streams: Beyond The Basics
49:21
Jfokus
Рет қаралды 72 М.
The Amazing Features of Modern Java  - Venkat Subramaniam
1:02:01
Developer Summit
Рет қаралды 29 М.
娜美这是在浪费食物 #路飞#海贼王
00:20
路飞与唐舞桐
Рет қаралды 4,8 МЛН