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

toBuilder() #72

Open
i-zanis-simply opened this issue Jun 19, 2023 · 2 comments
Open

toBuilder() #72

i-zanis-simply opened this issue Jun 19, 2023 · 2 comments

Comments

@i-zanis-simply
Copy link

Would it be possible to add a toBuilder() method?

@mfunaro
Copy link

mfunaro commented Feb 26, 2024

I would also like to see something like this on the target class. I usually create two builder methods on my target class, a toBuilder(this) and a static builder() method. It makes it convenient to create builders quickly with context.

Example:

public class TargetClass {

  private double value;
  
  private Targetclass(double value){
    this.value = value;
  }
  
  public static InnerBuilder builder(){
    return new InnerBuilder();
  }

  public InnerBuilder toBuilder(){
    return new InnerBuilder(this);
  }

//----------------------
  public static final class InnerBuilder {
  
      private double value;
  
      private InnerBuilder() {
      }
  
      private InnerBuilder(TargetClass other) {
        this.value= other.val;ue;
      }
  
      public InnerBuilder value(double value) {
        this.value = value;
        return this;
      }
      
      public InnerBuilder build(){
         return new TargetClass(value);
      }
   }
}

@kistlers
Copy link

kistlers commented Mar 8, 2024

I just discovered this plugin (it's great, thanks!) and immediately I missed these two methods being generated ffor inner class builders. Would be even better if the builder would not generate the public static aInner() {...}` method. Like the example from @mfunaro above that already did not include it.

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

3 participants