📜  kotlin 代码示例中的任何

📅  最后修改于: 2022-03-11 14:53:32.807000             🧑  作者: Mango

代码示例1
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 is also a Collection 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, List 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).