Let's break down:
BoardVO.builder().writer("테스터").build();
BoardVO is using Lombok with @Builder:Example:
@Data
@Builder
public class BoardVO {
private String writer;
// other fields...
}
@Builder is a Lombok annotation that automatically generates a builder class for BoardVO.
BoardVO.builder()BoardVO.BoardVOBuilder..writer("테스터")writer field in your BoardVO."테스터" to the writer field..build()BoardVO object using the values you set.BoardVO.Without using @Builder, this:
BoardVO.builder().writer("테스터").build();
Would look like this:
BoardVO board = new BoardVO();
board.setWriter("테스터");
But the builder pattern is especially helpful when:
"This line creates a builder object that matches the structure of the
BoardVOclass. Then, I can set values using the builder methods, and finally call.build()to create aBoardVOinstance with those values."
BoardVO.builder()
👉 Creates a builder object with the same fields as BoardVO.
.writer("테스터")
👉 Sets the writer field to "테스터" on the builder.
.build()
👉 Builds and returns a new BoardVO instance with writer set to "테스터".
So yes — the builder object mimics the structure of BoardVO, and each method like .writer() sets a field. It’s a very readable and safe way to create instances, especially when the class has many fields.
Let me know if you'd like a multi-field example too!