scala-for-the-impatient | Exercises of Scala for the Impatient | Build Tool library
kandi X-RAY | scala-for-the-impatient Summary
kandi X-RAY | scala-for-the-impatient Summary
Exercises of Scala for the Impatient.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scala-for-the-impatient
scala-for-the-impatient Key Features
scala-for-the-impatient Examples and Code Snippets
Community Discussions
Trending Discussions on scala-for-the-impatient
QUESTION
I am reading "Scala for the Impatient" and in 8.10 there is an example:
...ANSWER
Answered 2018-Apr-01 at 14:59def
s are called when asked for, but val
s are kept in memory, so in this case the val
version is still set to zero because it hasn’t been initialised, where the def
version is called and therefore can never give a misleading value.
It’s only because the val
here is overloaded that it isn’t initialised in time, because classes must be initialised starting at the top of the inheritance hierarchy and building down. If env
were a def
you’d be fine also, because it wouldn’t be created until called, by which time the val
s would all be initialised. Of course this way you’d get different lists every time you called env
so you might prefer to use lazy val
, which is initialised the first time it’s called, but then remains the same and is kept in memory.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scala-for-the-impatient
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page