All classes in java extend Object. All classes in ...
# getting-started
c
All classes in java extend Object. All classes in Kotlin extend Any. Why is that?
n
maybe to avoid confusion with
object
. maybe also because Kotlin is multiplatform and not every platform has
Object
r
Also, something like
List<Any>
is a bit more intuitive than
List<Object>
imao.
2
s
I interpreted this question to mean “why do all classes in Kotlin and Java inherit from a shared superclass”, and I found these interesting StackOverflow threads pertaining to C# https://stackoverflow.com/questions/1583482/why-does-every-class-in-net-inherit-from-object/1583524#1583524 https://softwareengineering.stackexchange.com/questions/157450/why-all-classes-in-net-globally-inherits-from-object-class
n
oh. I thought the question was why don't Kotlin classes extend the same class as Java classes.
s
That very well might’ve been the original intent 😅 I just thought y’all might still be interested in those threads
The fact that
java.lang.Object
isn’t cross-platform is probably the biggest reason though
n
maybe, but I'd be kinda impressed they were thinking that far ahead with Kotlin 1.0