Jersey Java を使用して不変オブジェクトを作成しようとしています。しかし、デフォルトのコンストラクターが大きなアプリケーションで役立つかどうかはわかりません。誰かがこれについて私を導くことができますか?
これは私のクラスです:-
package com.jersey.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
@XmlRootElement
@XmlType(name="todo")
@XmlAccessorType(XmlAccessType.FIELD)
@AutoProperty
public class Todo {
@XmlElement(name="summary")
private final String summary;
@XmlElement(name="description")
private final String description;
public String getSummary() {
return summary;
}
public String getDescription() {
return description;
}
private Todo(){
this(new Builder());
}
private Todo(Builder builder){
this.summary = builder.summary;
this.description = builder.description;
}
@Override
public boolean equals(Object o) {
return Pojomatic.equals(this, o);
}
@Override
public int hashCode() {
return Pojomatic.hashCode(this);
}
@Override
public String toString() {
return Pojomatic.toString(this);
}
public static class Builder{
private String description;
private String summary;
public Builder summary(String summary){
this.summary = summary;
return this;
}
public Builder description(String description){
this.description = description;
return this;
}
public Todo build(){
return new Todo(this);
}
}
}
デフォルトのコンストラクタも同様です:-
private Todo(){
this(new Builder());
}
シリアライゼーション/デシリアライゼーションに役立つか、まったく役に立ちません。
大きなアプリケーションでどのような影響があるか、またはすべてを使用しない方がよいかはわかりません。