0

不确定标题是否合适,但这是我的问题

我写了一个类,例如,

版本 1

class SomeClass
{
    public method1()
    {
        ...
        ...
    }

    public method2()
    {
        ...
        ...
    }
}

SomeClass 的对象被不同的模块推送到消息队列中说

module1
module2
module3

然后正在处理module4

现在,module3需要一些额外的功能 method3() 所以我向 SomeClass 添加了额外的功能

第 2 版

class SomeClass
{
    public method1()
    {
        ...
        ...
    }

    public method2()
    {
        ...
        ...
    }

    public method3()
    {
        ...
        ...
    }
}

并更新module3module 4使用这个新类,但是 module1 和 module2 不是

module3SomeClass(版本 2)的对象发布到消息队列,但是module1仍然module2发布SomeClass(版本 1)的对象

module 4具有版本 2 定义的读取版本 1 定义的对象会有任何问题吗?

4

1 回答 1

1

Theoretically it could work because when you push object to message queue (using ObjectMessage) it is serialized using standard java serialization mechanism. Serialization does not care about methods. It uses fields only. It means that you can serialize object v1 and then deserialze it using class version 2. But I believe you will have to add special field private static long serialVersionUID to your class and manage its value manually.

So, your v1 and v2 that have identical number and order of field and differ by methods only will have the same serialVersionUID.

于 2012-10-26T16:03:56.597 回答