Project Lombok @Builder with generics

When I first put @Builder on a generic class I was confronted with a compiler error.

@Builderpublic class Response {  private T body;} Response<String> response = Response.builder().body("body").build();

The compiler complains about an incompatible assignment, as the result of the build process is Response<Object>. What’s required is a hint for the compiler when creating the builder, you’ll have to specify the requested type explicitly when creating the builder:

Response<String> response = Response.<String>builder().body("body").build();