Skip to content

Instantly share code, notes, and snippets.

@vojtechruz
Last active May 11, 2016 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtechruz/6f68a37dc09e962aa1a228822f51fe3d to your computer and use it in GitHub Desktop.
Save vojtechruz/6f68a37dc09e962aa1a228822f51fe3d to your computer and use it in GitHub Desktop.
Example of telescoping constructor
public class Person {
private final String firstName;
private final String lastName;
private final String description;
private final int age;
public Person(String firstName, String lastName) {
this(firstName, lastName, "No description available");
}
public Person(String firstName, String lastName, String description) {
this(firstName, lastName, description, -1);
}
public Person(String firstName, String lastName, String description, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.description = description;
this.age = age;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment