-1

Hi I'm having the following piece of code

        BBResponse bbStmtResponse = BBResponse.builder().result(IN_PROGRESS).build();

After few validations, I want to update the object "bbStmtResponse" to set to other properties as

bbStmtResponse.builder().status(SUCCESS).build();

When I print the bbStmtResponse object, it doesn't hold "result" property value which was supposed to be"IN_PROGRESS". How can I overcome this, instead of using setter methods as there are more properties to set

Syed
  • 2,471
  • 10
  • 49
  • 89
  • it looks like you would need to take a "previous" instance in the `builder` method - if you understand what Builder pattern does, then it would be a lot easier for you. There is not much to "overcome" - when you call `builder()` - you initiate a new Object creation – Eugene Mar 01 '20 at 14:20

1 Answers1

1

Two ways:

  • Use toBuilder method
@Builder(toBuilder = true)
public BBResponse

Then use bbStmtResponse.toBuilder().status(SUCCESS)

  • Use @Setter to enable both builder and setter:
@Setter
@Builder(toBuilder = true)
public BBResponse
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51