

It differs to Javas Object in 2 main things. Calls the specified function block with this value as its receiver and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure. Any can’t hold the null value, if you need null to be part of your variable you can use the type Any? In Kotlin the Any type represents the super type of all non-nullable types.

In Java, primitives types aren’t type of the hierarchy and you need to box them implicitly, while in Kotlin Any is a super type of all types.It differs to Java’s Object in 2 main things: In Kotlin the Any type represents the super type of all non-nullable types. Start learning Kotlin now » Examples in Each Chapter Our 'Try it Yourself' editor makes it easy to learn Kotlin. Kotlin is used to develop Android apps, server side apps, and much more. Kotlin is easy to learn, especially if you already know Java (it is 100 compatible with Java). Object is the root of the class hierarchy in Java, every class has Object as a superclass. Kotlin is a modern, trending programming language. We will see here how Kotlin represent these types and how it improves them. Java has Object to represent the root of the class hierarchy and voidto represent the lack of a type. Photo by Mr Cup / Fabien Barral on Unsplash
