5 Secret Java API Tricks and Record Semantics - Inside Java Newscast #4

preview_player
Показать описание
#Java #OpenJDK #JDK
Five nifty Java API features that you need to know (and many more in the linked thread) and a quick explanation why Java records are not about reducing boilerplate.

⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro
0:23 5 Tips
0:59 5 Tips - Pattern::asPredicate
1:25 5 Tips - Named RegEx Capturing Groups
2:07 5 Tips - Predicate::not
2:46 5 Tips - Comparator::naturalOrder
3:20 5 Tips - AutoClosable Streams
4:04 Record Semantics
6:32 Outro
Рекомендации по теме
Комментарии
Автор

I really liked the asPredicate method on Pattern, and named groups in regex (very handy as there is no need to count the index groups).

SourabhBhat
Автор

Wow, the named Regex group thing is awesome.

edburns
Автор

Streams API is game changer for Java Developer, it is worth putting effort to learn it. Thank you for this newscast, makes developers aware of less know tricks and provides clarity and conceptual level. Thought that Records are tuple changes the perspective we had.

msrgopinathn
Автор

There is so much to learn about streams API, deep!

abhishekdanej
Автор

One thing I _really_ miss with records is the possibility to clone a record with just one different value with autogenerated methods. Say we have a record "Point3D", it would be nice to write:
var p1 = new Point3D(20, 30, 40);
var p2 = p1.withZ(10);
instead of:
var p1 = new Point3D(20, 30, 40);
var p2 = new Point3D(p1.x, p1.y, 10);
With every additional parameter, writing the complete constructor gets more tedious. I argue (here's your own argument) that a "modified copy" functionality is generally needed, plus there is a good default implementation for it:
public Point3D withZ(int z){ return new Point3D(x, y, z); }
Contrary to the "with-blocks" that you describe in your blog post, these do not require any new syntax, don't look strange, can be chained naturally and will cope perfectly with a compiler's escape analysis, i.e. they should be mega cheap to implement.

brixomatic
Автор

Nice. If you could slow down a bit that would be great.

nithinnambiar
Автор

Whenever I hear Java, I always think of Minecraft Java Edition lol

nooristicc
visit shbcf.ru