Java Records

preview_player
Показать описание
A Java Record is a special type of Java class specifically designed to represent a data record, like records returned from a database or remote service. Java Records offer a more concise syntax than defining POJOs the old school way. Java Records is a new feature in Java 14.
Java Records is still a preview features, so we don't know yet if records will stay in Java. In order to use Java Records you must thus switch preview feature on in your Java SDK / IDE.

Java Records are immutable, by the way, so once created you cannot change the values stored in the record instance.

Chapters
0:00 Java Record introduction
1:46 Java Record example
2:30 What the Java compiler auto-generates for you in a Java Record
5:13 Extra constructors in a Java Record
6:31 Instance methods in a Java Record
7:35 Static methods in a Java Record

Java Record Tutorial - textual version:
Рекомендации по теме
Комментарии
Автор

When it comes to teaching Java language concepts and features, Jenkov is one of the best teachers I've come across and I've been coding in Java for over 20 years.
Thanks for a great video on the new Java 14 features.

carlellis
Автор

Hi Jakob. I'm a Java beginner and my brother recommended me your website. It is helping me a lot. Thanks!!

ivanyoed
Автор

Jakob i would like to thank you so much for the amazin blog
Pure gold mate!

AlouiMohamedhabib
Автор

you are my guru for java.Thanks a lot for helping me all such years.You are a genius for me.

AdityaRajVerma
Автор

Jakob, I've just stumbled on your blog searching for an unrelated topic (if it helps you with SEO it was the single test "if(true) in java" typed into Google) and I must say that your site is the easiest to use. The whole menus are neatly arranged with big blue letter describing accurately the topics in question. The headlines for each topic are easy to understand, concise and on point. To sweeten the pot you've added a video about Records in java which I didn;t know existed but it was at the top right of the page. Good position of the video, up to date. Overall a clean website, my hat to you. You've won a subscriber and a recurring visitor. Thank you

alexandruandronache
Автор

I really like your explanation step by step and very clean.

jayeshdalal
Автор

Nice video.
Since the record is immutable, I assume the compiler will generate the fields as final, prohibiting you from defining instance methods that mutate the field references?

androkles
Автор

A usefull feature which reduces boilerplate code.

veerabhadrudu.s
Автор

Thanks so much! Do Records have builders generated for them? Or... is it expected that they will eventually?

scody
Автор

Finally, java has case classes.... which scala had already a long time ago. Well maybe in a few years Java will finally turn into Scala.

uriakramer
Автор

record => class + some lombok features

tdilber
Автор

You said that no setters in place for record. Any update on this?
Thank you!

higiniofuentes
Автор

Nice tutorial. Thanks. One question, Is it possible to establish relationships between entities(records) like OneToMany, ManyToMany etc?

omnipoten
Автор

i wonder what is the syntax of "this" in java, and what is it used for? how does it work?

_ngurahkomangwiragaliha
Автор

I think this feature is redundant on a big projects, cause it can bring you Telescoping constructor anti-pattern problems. Any builder works better. You can leave unused parameters and they will be null by default.

victorzagrebin
Автор

Could you please update your app to support dark mode in playstore. Thanking you for your support and selfless help!

amalangelraj
Автор

please the parenthesis on the print u can keep them tight... and the .equals() u dont have to indent it. over-exaggerating readibility is counterproductive. these are subjective cosmetic fine lines :)

ademord
Автор

I am confused why record class needs the empty curly braces?

Rogueixpresents