So I have to make a presentation about class any in Kotlin, I'm a complete beginner so I don't know much, if anybody can link to class any docs or explain in few words what it does or how it works.
thanks in advance.
Any
is the root of the Kotlin class hierarchy. What this means is that every* value in Kotlin is implicitly an Any
.
In the same way that every List<T>
is also a Collection<T>
and every Integer
and Double
is also a Number
, every* single value in Kotlin is also an Any
.
If a method accepts an Any
parameter, it means it accepts, well, literally any* type of value, be it String
, Integer
, Array<Animal>
, List<Foo>
MyCoolClass
or anything else.
*) Aside from null
. Any
covers all non-null
values. Similarly, Any?
means "Any
, but this time also including null
".
If you're familiar with Java, Any
is Kotlin's counterpart to Java's Object
which is the root of every type of value (aside from primitives).