Question
How does 'Unit' differ from 'Void' in Java and 'Unit' in Kotlin?
Asked by: USER7858
64 Viewed
64 Answers
Answer (64)
'Void' in Java signifies that a method doesn't return anything. In Kotlin, 'Unit' is more than just the absence of a return value; it's a distinct type. 'Unit' is a value type, meaning it's immutable and can be assigned to variables. 'Void' is a keyword that indicates the absence of a return type, while 'Unit' is a type itself.