这是我的类Offer的代码,当我编译这部分代码时出现错误..请帮帮我。你的家伙
import java.io.Serializable;
public class Offer implements Comparable<Object>, Serializable {
private static final long serialVersionUID = 1L;
private Product product;
private RegisteredUser user;
private float amount;
//stati dell'offerta
private OfferState bestOffer;
private OfferState overtakenOffer;
private OfferState winnerOffer;
private OfferState loserOffer;
//stato attuale dell'offerta
private OfferState state;
public Offer(){}
public Offer(Product product, RegisteredUser user, float amount)
{
this.user = user;
this.amount = amount;
this.product = product;
bestOffer = new BestOffer(this);
overtakenOffer = new OvertakenOffer(this);
winnerOffer = new WinnerOffer(this);
loserOffer = new LoserOffer(this);
state = bestOffer;
}
public RegisteredUser getUser() {
return user;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
@Override
public int compareTo(Object arg0) {
return Float.compare(amount, ((Offer) arg0).getAmount());
}
public OfferState getBestOffer() {
return bestOffer;
}
public OfferState getOvertakenOffer() {
return overtakenOffer;
}
public OfferState getWinnerOffer() {
return winnerOffer;
}
public OfferState getLoserOffer() {
return loserOffer;
}
public OfferState getState() {
return state;
}
public void setState(OfferState state) {
this.state = state;
}
public void reciveOffer()
{
try
{
state.reciveOffer();
}
catch (UnsupportedOperationException e) {
}
}
public void deadline()
{
try
{
state.deadline();
}
catch (UnsupportedOperationException e) {
}
}
public Product getProduct() {
return product;
}
}
答案 0 :(得分:1)
Product,RegisteredUser,OfferState等所有成员也必须可序列化或标记为瞬态。我认为他们不是你必须做的。这里有一个很好的例子: Serialization - readObject writeObject overrides