Java 14: A Simple Record 📎
record
:
public record Article(String title, String content) {}
...is a ready to use Data Transfer Object (DTO).
equals
,hashCode
, toString
and private final
field with corresponding accessors are generated as well.
The following code:
var article = new Article("java 14", "hello,record");
System.out.println("article = " + article + " " + article.content() + " " + article.title());
prints the following output:
article = Article[title=java 14, content=hello,record] hello,record java 14
See it in action and "from scratch" in 4 mins: