Created
April 26, 2019 11:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @AllArgsConstructor | |
| public class Animal { | |
| private int age; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Cat cat = Cat.builder() | |
| .age(2) | |
| .name("Ginger") | |
| .owner("Felix") | |
| .build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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