Skip to content

Commit

Permalink
Convert record to class
Browse files Browse the repository at this point in the history
  • Loading branch information
DManstrator committed Jun 14, 2023
1 parent 08ee53c commit 3171739
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
package tk.dmanstrator.sb3_serialization_test.entity;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public record CustomObject(String hello, List<String> world) implements Serializable {}
public class CustomObject implements Serializable {

@Serial
private static final long serialVersionUID = 0L;

private final String hello;
private final List<String> world;

// Default Constructor needed for (de)serialization.
public CustomObject() {
this("", new ArrayList<>());
}

public CustomObject(String hello, List<String> world) {
this.hello = hello;
this.world = world;
}

public String getHello() {
return hello;
}

public List<String> getWorld() {
return world;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (CustomObject) obj;
return Objects.equals(this.hello, that.hello) &&
Objects.equals(this.world, that.world);
}

@Override
public int hashCode() {
return Objects.hash(hello, world);
}

@Override
public String toString() {
return "CustomObject{" +
"hello='" + hello + '\'' +
", world=" + world +
'}';
}

}

0 comments on commit 3171739

Please sign in to comment.