Java: how to make this serializable?
•
Java
I need the following class to be 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; } }
So far, I can't send it as an object with OutputStream I tried to implement serializable, but it didn't work
Solution
Implementing serializable will work, but you must write objects using objectoutputstream, not just OutputStream
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码