问题
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