question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generic Builder should not need explicit type for build method

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
violplayercommented, Jul 15, 2016

screen

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…

0reactions
violplayercommented, Jan 6, 2017

Hello @mplushnikov, thanks for your effort. Seems to be fixed in version 0.13.14.

Best regards Sven

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found