Value Definitions and Termination

The difference between val and def becomes apparent when the right hand side does not terminate.
Given
def loop: Boolean = loop
A definition
def x = loop
is OK, but a definition
val x = loop
will lead to an infinite loop.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala snippets
Cosmo
Sign Up Now
or Subscribe for future quizzes