Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Value
- @Builder
- static class E {
- @NonNull String x;
- @NonNull Integer y;
- @NonNull Long z;
- }
- @Test(expectedExceptions = {NullPointerException.class})
- public void testBuilder() throws Exception {
- // the test shows how to suppress nulls in the immutable values
- val e = E.builder()
- .x(null)
- .y(213)
- .z(43782L)
- .build();
- System.out.println("e = " + e);
- }
- // the compiler outputs the following bytecode: (the source is obtained by decompilation)
- static final class E {
- @NonNull
- private final String x;
- @NonNull
- private final Integer y;
- @NonNull
- private final Long z;
- E(@NonNull String x, @NonNull Integer y, @NonNull Long z) {
- if(x == null) {
- throw new NullPointerException("x");
- } else if(y == null) {
- throw new NullPointerException("y");
- } else if(z == null) {
- throw new NullPointerException("z");
- } else {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- }
- public static MatchingTest.E.EBuilder builder() {
- return new MatchingTest.E.EBuilder();
- }
- @NonNull
- public String getX() {
- return this.x;
- }
- @NonNull
- public Integer getY() {
- return this.y;
- }
- @NonNull
- public Long getZ() {
- return this.z;
- }
- public boolean equals(Object o) {
- if(o == this) {
- return true;
- } else if(!(o instanceof MatchingTest.E)) {
- return false;
- } else {
- MatchingTest.E other;
- label44: {
- other = (MatchingTest.E)o;
- Object this$x = this.getX();
- Object other$x = other.getX();
- if(this$x == null) {
- if(other$x == null) {
- break label44;
- }
- } else if(this$x.equals(other$x)) {
- break label44;
- }
- return false;
- }
- Object this$y = this.getY();
- Object other$y = other.getY();
- if(this$y == null) {
- if(other$y != null) {
- return false;
- }
- } else if(!this$y.equals(other$y)) {
- return false;
- }
- Object this$z = this.getZ();
- Object other$z = other.getZ();
- if(this$z == null) {
- if(other$z != null) {
- return false;
- }
- } else if(!this$z.equals(other$z)) {
- return false;
- }
- return true;
- }
- }
- public int hashCode() {
- int PRIME = true;
- int result = 1;
- Object $x = this.getX();
- int result = result * 59 + ($x == null?43:$x.hashCode());
- Object $y = this.getY();
- result = result * 59 + ($y == null?43:$y.hashCode());
- Object $z = this.getZ();
- result = result * 59 + ($z == null?43:$z.hashCode());
- return result;
- }
- public String toString() {
- return "MatchingTest.E(x=" + this.getX() + ", y=" + this.getY() + ", z=" + this.getZ() + ")";
- }
- public static class EBuilder {
- private String x;
- private Integer y;
- private Long z;
- EBuilder() {
- }
- public MatchingTest.E.EBuilder x(String x) {
- this.x = x;
- return this;
- }
- public MatchingTest.E.EBuilder y(Integer y) {
- this.y = y;
- return this;
- }
- public MatchingTest.E.EBuilder z(Long z) {
- this.z = z;
- return this;
- }
- public MatchingTest.E build() {
- return new MatchingTest.E(this.x, this.y, this.z);
- }
- public String toString() {
- return "MatchingTest.E.EBuilder(x=" + this.x + ", y=" + this.y + ", z=" + this.z + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement