Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] @SuperBuilder error info : java: incompatible type: capture#1, total? cannot be converted to #2708

Open
killerover84 opened this issue Jan 12, 2021 · 10 comments

Comments

@killerover84
Copy link

killerover84 commented Jan 12, 2021

use @SuperBuilder report error : java: incompatible type: capture#1, total? cannot be converted to
image

@killerover84 killerover84 changed the title [BUG] @SuperBuilder error info :java: 不兼容的类型: capture#1, 共 ?无法转换为XXX [BUG] @SuperBuilder error info : java: incompatible type: capture#1, total? cannot be converted to Jan 12, 2021
@janrieke
Copy link
Contributor

We need an example to reproduce.

@killerover84
Copy link
Author

killerover84 commented Jan 12, 2021 via email

@arsalans
Copy link

Is there any work going on this issue with SuperBuilder? Running into the same issue:

incompatible types: java.util.List<capture#1 of ?> cannot be converted to java.util.List<com.company.MyObject>

@janrieke
Copy link
Contributor

janrieke commented Jul 20, 2023

Difficult to say without source code. You probably have a type parameter on your class and javac is unable to infer the type through your chained builder method calls. Add a type hint to your builder() method call.

@arsalans
Copy link

Sorry, how do you add a type hint to a Builder()?

@janrieke
Copy link
Contributor

You should post your code.

@arsalans
Copy link

arsalans commented Jul 20, 2023

Alright, I have a TestResponse class that is annotated as follows:

@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TestResponse extends SomeParent {

    private Integer autoNumber;
    private List<String> autoDischarges;

}

I am using this class like this (returning as a response object):

public List<TestResponse> getAutoDischarges() {
       List<String> allRecords = List.of(**Something**);
       return allRecords 
               .stream()
               .map(driver -> TestResponse
                       .builder()
                       .autoDischarges(List.of(**something else**))
                       .autoNumber(1)
                       .build())
               .toList();
   }

The above code has a compile error saying the following:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project p**d: Compilation failure
[ERROR] /C**.java:[65,24] incompatible types: java.util.List<capture#1 of ?> cannot be converted to java.util.List<com.****.TestResponse>

@janrieke
Copy link
Contributor

public List<TestResponse> getAutoDischarges() {
    List<String> allRecords = List.of();
    return allRecords 
            .stream()
            .<TestResponse>map(driver -> TestResponse
                    .builder()
                    .autoDischarges(List.of())
                    .autoNumber(1)
                    .build())
            .toList();
}

@janrieke
Copy link
Contributor

janrieke commented Jul 21, 2023

BTW: The code from the original poster compiles and works, so this issue can be closed. Probably a bug from the early days of IntelliJ's @SuperBuilder support.

@dding94
Copy link

dding94 commented Feb 22, 2024

@arsalans

If you check the ByteCode of the Builder that is created when you declare SuperBuilder, you can see that it uses wildcards, so you need to explicitly declare the type to prevent type casting in stream operations.

스크린샷 2024-02-23 오전 1 44 54 스크린샷 2024-02-23 오전 1 45 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants