Created
June 24, 2020 13:22
This file contains 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
package com.hubspot; | |
import java.io.Serializable; | |
import java.util.Objects; | |
public class SomeClass implements Serializable { | |
private final long id; | |
private final String name; | |
private SomeClass(long id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
public static Builder builder() { | |
return new Builder(); | |
} | |
public long getId() { | |
return id; | |
} | |
public String getName() { | |
return name; | |
} | |
public static final class Builder { | |
private Long id = null; | |
private String name = null; | |
private Builder() {} | |
public Builder setId(Long id) { | |
this.id = id; | |
return this; | |
} | |
public Builder setName(String name) { | |
this.name = name; | |
return this; | |
} | |
public SomeClass build() { | |
Objects.requireNonNull(id, "id"); | |
Objects.requireNonNull(name, "name"); | |
return new SomeClass(id, name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment