gpt4 book ai didi

java - 在java中实现接口(interface)

转载 作者:行者123 更新时间:2023-12-01 13:49:43 25 4
gpt4 key购买 nike

我正在使用java中的接口(interface)。我想将数据放入文件中,当我编译程序时出现此错误:

java.io.InvalidClassException: Teatro; local class incompatible: stream classdesc      serialVersionUID = -8638492166751354209, local class serialVersionUID = 8721614984870769537
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at CarteleraProg.main(CarteleraProg.java:107)

error Teatro; local class incompatible: stream classdesc serialVersionUID = -8638492166751354209, local class serialVersionUID = 8721614984870769537

 public interface Playable {

public void ImprimirDatos();

}

public void ImprimirDatos(){
System.out.println ("TITULO TEATRO: " + getTitulo());
System.out.println ("DIRECTOR: " + getDirector());
System.out.println ("ESCENOGRAFO: " + getEsceno() );
System.out.println ("FECHA: " + getFecha());
}

我可以做什么来解决这个问题?

非常感谢

最佳答案

您(或您使用的库)已更改类 Teatro 以创建另一种串行格式(更改/添加/删除成员,更改父类(super class),...)之后 您已将 Teatro 类的对象写入流。

如果您确实确定,请使用固定 ID:

public class Teatro implements Serializable {
private static final long serialVersionUID = -8638492166751354209L;

...
}

关于java - 在java中实现接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20057972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com