Skip to content

Instantly share code, notes, and snippets.

@mikybars
Created April 26, 2019 11:20
Show Gist options
  • Select an option

  • Save mikybars/2a0d965700f92e9427eaa44036869901 to your computer and use it in GitHub Desktop.

Select an option

Save mikybars/2a0d965700f92e9427eaa44036869901 to your computer and use it in GitHub Desktop.
The `@AllArgsConstructor` annotation in the superclass is handy for generating the constructor with all the parameters in the subclass. In IntelliJ, for example, the `Generate->Constructor` helper automatically inserts the parameters belonging to the
@AllArgsConstructor
public class Animal {
private int age;
}
Cat cat = Cat.builder()
.age(2)
.name("Ginger")
.owner("Felix")
.build();
public class Cat extends Animal {
private String name;
private String owner;
@Builder
public Cat(int age, String name, String owner) {
super(age);
this.name = name;
this.owner = owner;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment