The basic types such as Int
, Double
, Char
, etc. are represented on the JVM in one of two ways (documentation):
- whenever possible, as primitives (
int
, double
, char
),
- when required to be nullable or when used as generic type parameters, as the respective wrapper classes (
Integer
, Double
, Character
).
Both of these representations are serializable. Primitive types are serializable by default as they are, and their wrappers all implement Serializable
as well, for example, as you can see in the documentation of Character
.
This sort of mapping between Kotlin and Java types is also mentioned here in the Java interop documentation.
So the question is, why don't the Kotlin representations have Serializable
as a supertype on the source code level? My guess is so that they're kept platform independent, as having them explicitly implement java.io.Serializable
would make them depend directly on a JVM type.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…