简体   繁体   English

扩展可序列化的类时的警告

[英]Caution while extending a class which is Serializable

I have a class A implementing Serializable and another class B extends A , but I want to use class B for XML binding, not for serialization. 我有一个实现Serializable的类A ,另一个B extends A类,但我想将B类用于XML绑定,而不用于序列化。

Is there anything I should worry about? 我有什么需要担心的吗?

Assuming you've implemented all of the Serializable methods in A , nope. 假设您已经在A实现了所有Serializable方法,不行。 You won't need to worry about implementing them, since that's already done. 您无需担心实现它们,因为已经完成了。 If there are any naming conflicts between XML binding and serialization, you can define the method in B and your XML binding library will call the methods for B , not those of A (ie polymorphism ). 如果XML绑定和序列化之间存在命名冲突,则可以在B定义方法,并且XML绑定库将为B调用方法,而不是为A调用方法(即, 多态 )。

The only potential worry is a method that takes an argument of type Serializable -- if B , for whatever reason, shouldn't be (de)serialized, this is a problem. 唯一潜在的麻烦是采用类型为Serializable的参数的方法-如果无论出于何种原因都不应该对B进行(反)序列化,则这是一个问题。 I doubt that this is a problem for you, if only because there are so few cases when it would apply. 我怀疑这对您来说是一个问题,仅是因为很少有情况适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM