What is a Unit in Kotlin?

Unit corresponds to the void keyword in Java.

What is a Unit in Kotlin?

If you have a function that does not return a value, you can return a Unit object.

Generally, you would return a Unit in Kotlin where you would traditionally return a void in Java.

fun doesntReturnAnythign(): Unit { val one = 1 }
Code language: Kotlin (kotlin)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments