aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/experimental/WitherExample_post.jpage
blob: 3447192a03fe7030156e4ef4993ded27e7d755e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import lombok.NonNull;

public class WitherExample {
	private final int age;
	private @NonNull final String name;

	public WitherExample(String name, int age) {
		if (name == null) throw new NullPointerException();
		this.name = name;
		this.age = age;
	}

	public WitherExample withAge(int age) {
		return this.age == age ? this : new WitherExample(name, age);
	}

	protected WitherExample withName(@NonNull String name) {
		if (name == null) throw new java.lang.NullPointerException("name");
		return this.name == name ? this : new WitherExample(name, age);
	}
}