Why does AtomicInteger implements Serializable

。_饼干妹妹 提交于 2019-12-23 09:25:39

问题


Accoriding to javadoc,

public class AtomicInteger extends Number implements java.io.Serializable {

// code for class

}

But,

public abstract class Number implements java.io.Serializable {
//code for class
}

If Number class already implements java.io.Serializable then why do AtomicInteger implements it again?

Edit: Does Serializable being a marker interface makes any difference in this context?


回答1:


Just to document it more clearly. Same situation with the abstract collection base classes.

Could also have been a mistake initially (that is now carried forward for consistency's sake).




回答2:


There is no necessity as such, it is just for the sake of documentation.




回答3:


It is a good practice, and more for readable purpose. The same case with HttpServlet and GenericServlet. There are lot of other implementations in java sdk which follows this.




回答4:


Does Serializable being a marker interface makes any difference in this context?

No difference at all. There is nothing special about a marker interface at the linguistic level.



来源:https://stackoverflow.com/questions/11028542/why-does-atomicinteger-implements-serializable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!