Java:如何使这个Serializable?
发布时间:2020-12-15 08:45:07 所属栏目:Java 来源:网络整理
导读:我需要以下类是Serializable. package helpers;public class XY implements ComparableXY{ public int x; public int y; public XY (int x,int y) { this.x = x; this.y = y; } public int compareTo( XY other ) { String compare1 = this.x + "-" + this.y
|
我需要以下类是Serializable.
package helpers;
public class XY implements Comparable<XY>
{
public int x;
public int y;
public XY (int x,int y)
{
this.x = x;
this.y = y;
}
public int compareTo( XY other )
{
String compare1 = this.x + "-" + this.y;
String compare2 = other.x + "-" + other.y;
return compare1.compareTo( compare2 );
}
public String toString()
{
return this.x + "-" + this.y;
}
}
截至目前,我不能将它作为一个对象与outputstream一起发送..我试图实现Serializable,但这不起作用. 解决方法
实现Serializable会起到作用,但是你必须使用
ObjectOutputStream编写对象,而不仅仅是OutputStream.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
