What is a Record? - Cracking the Java Coding Interview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 95: What is a Record?
Рекомендации по теме
Комментарии
Автор

This is good. I literally just read about records 2 days ago in a Java design pattern book I'm reading. I feel like they are a little problematic, but they are right for a very narrow use case. They seem to pair well with abstract factory patterns.

walimorris
Автор

you can not use it all the time, e.g. it will be problematic to use it with Hiberante Entity or as a SpringBean

yilativs
Автор

I think records pair very well with Lombok annotation like @Builder and @With, the latter allows us to create a new instance from base object but with only one field change.

VuLinhAssassin
Автор

Wrong variable name in validation: if (range > end) {…}. It should be if (begin > end) {…}

jjupitertv
Автор

Jose can u explain a static keyword by taking a real time example?

gantajayanth
Автор

@JosePaumard where can we find the whole series of cracking the java coding interview ordered ascending please?

The idea is to watch them in a sequential way .

Thanks in advance

emileastih
Автор

Once I used record for @Service spring class. A coworker said it was a bad idea (injected bean are exposed, some unused method are implemented toString … etc )

I used a record for this in order to have my injected field final (and also to write less code to be honest)

What is your opinion for this case ?

Ps: by default I use a record. I eventually thing use a class if I have specific needs

lepaludyves
Автор

Its to bad that the record constructor is forced to be ALWAYS public. If you could make it private then it would be possible to also make a deduplication instance cache... But sadly that isn't possible and you are forced to stay with classes...

Speiger
Автор

Record will be better if it doesn't have the useless {}. I think it should be omitted if it is unused, as same as Kotlin's data class.

alskaa
Автор

I could use records more, but once it doesn't permit setters, it limits my uses

sergios