Converting an Map.Entry into a Java 14 Record

preview_player
Показать описание
Java 14 records are a convenient way for data transformations inside a Java stream.
Рекомендации по теме
Комментарии
Автор

Can you make a video on streams and lambdas? Which was introduced in java8. They are confusing

Videoorchard
Автор

Instead of having to add an extra constructor on each record, just create a helper which can accept a constructor of any record of 2 fields, or any other bi-function:

<K, V, R> Function<Entry<K, V>, R> entry(final BiFunction<? super K, ? super V, ? extends R> f)

usage:

evelopers.entrySet()
.stream()
.map(entry(Developer::new))

kce
Автор

I can do the same thing with the simple java class, what's the point? Less code and that's all?

alexnerd