Abhinay Kumar
Abhinay Kumar

Reputation: 111

lombok @Builder type cast error

I am new in lombok library. I am using @Builder pattern of lombok but it return generic of Object type:

@Data
@Builder
public class Schedule<T>
{
    private String frequency;
    private T properties;
}

From calling class:

Abc abc=new Abc();
//other
Schedule<Object> schedule=Schedule.builder().frequency( "ankit" ).properties( abc ).build();

i want result in Schedule<Abc> but getting Schedule<Object>.

Thanks and respond as soon as possible.

Upvotes: 4

Views: 1737

Answers (2)

ankit
ankit

Reputation: 2845

This is not a issue of lombok.you need to type cast it to Your class Abc. For type cast you need to follow syntax:

T<M> t=T.<M>builder()
        .variablename("set value")
        .build();

as answered by @Micha: https://stackoverflow.com/a/51873129/6097074

Upvotes: 4

micha
micha

Reputation: 49582

You need to pass Abc as generic parameter to builder():

Schedule<Abc> schedule = Schedule.<Abc>builder() .frequency( "ankit" ) ^^^ .properties( abc ) .build();

Upvotes: 3

Related Questions