Java: How to make this Serializable?

前端 未结 3 505
误落风尘
误落风尘 2021-01-18 19:31

I need the following class to be Serializable.

package helpers;

public class XY implements Comparable
{
    public int x;
    public int y;

    p         


        
相关标签:
3条回答
  • 2021-01-18 19:54

    Please see the SerializationUtils API provided by Apache Commons Lang.

    This is much safer and more maintenance friendly. :)

    0 讨论(0)
  • 2021-01-18 20:06

    Implementing Serializable will do the trick, but you must write the object with an ObjectOutputStream, not just an OutputStream.

    0 讨论(0)
  • 2021-01-18 20:08

    You just need to inherit from java.io.Serializable:

    public class XY implements Comparable<XY>, java.io.Serializable

    Check more about serialization here.

    0 讨论(0)
提交回复
热议问题