What is Unit in Scala? What is the difference between Java’s void and Scala’s Unit?
Answer Posted / Pappu Kumar Choudhary
Unit is a special type in Scala, similar to void in Java, but they have some differences. While void in Java signifies the absence of a return value for a method, Scala's Unit represents an empty value (similar to Null or Nothing in other languages). The key difference is that Scala functions always implicitly return Unit if no return type is specified, while Java methods with a return type of void explicitly state that they don't return any value.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers