Generic Builder should not need explicit type for build method
See original GitHub issueThe following code shows a warning about usage of raw types when build() is called although the type of the builder b is well defined as Test.TestBuilder<String>.
import lombok.Builder;
import lombok.Value;
@Builder
@Value
public class Test<T> {
T value;
public static void main(String[] args) {
final TestBuilder<String> b = Test.<String>builder().value("a");
final Test<String> t = b.build();
}
}
This warning can only be removed when replacing with
final Test<String> t = b.<String>build();
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Java generics + Builder pattern - Stack Overflow
If you only use this builder yourself, just go for it. However, if there are other developers, my answer could be easier for...
Read more >Project Lombok's @Builder annotation and generics
Note the explicit type statement <String> right in front of the builder() method invocation. This is used to help the compiler choose the...
Read more >Using @Builder with generics - Google Groups
1. I have used the builder incorrecty. When using EntityBuilder.<String>builder().build() I can assign without trouble to Entity<String> entity ...
Read more >@Builder - Project Lombok
If you do have an explicit constructor, put the @Builder annotation on the constructor instead of on the class.
Read more >Function builder cannot infer generic parameters even though ...
Explicit type annotation for variable bindings within the body, but inferred closure type. This would be enabled by one-way constraints. It's ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Native lombok doesn’t know about generic type because of type erasure. I just added a screenshot that shows that at least in the structure, you can see the build() method return Data<T> and does not need static type added to the call.
[Edit - added] Sorry I cannot make any test with eclipse, I didn’t manage to get Neon working in appropriate time…
Hello @mplushnikov, thanks for your effort. Seems to be fixed in version 0.13.14.
Best regards Sven