Starter lesson
Model a task with a record
Records reduce boilerplate for data carriers while providing value-based equality. They are a useful building block for API and domain models.
import java.util.List;
record Task(String title, boolean ready) {}
class Main {
public static void main(String[] args) {
var tasks = List.of(
new Task("Review changes", true),
new Task("Run tests", false)
);
tasks.stream()
.filter(Task::ready)
.map(Task::title)
.forEach(System.out::println);
}
}
What to expect
Review changes
Key idea: Use small immutable value types to make the shape and meaning of application data clear.