lazy evaluation : Java Glossary

lazy evaluation
In computing, laziness is a virtue. The more ways you can think of to have the computer avoid doing work, the faster your programs will run.

It can often be optimal in computing to procrastinate computation to the last possible microsecond. If you are lucky, the computer never needs to do the work.

One common example of procrastination is to use a singleton object instead of static fields. You don’t create the object until you actually need it. Just before every use, you must execute code roughly like this:

if ( singleton == null )
   {
   singleton = new Something();
   // further initialisation code ...
   }

Two other procrastination examples:

The && operator in Java avoids evaluation the right hand operand if the left hand operand is false. This is sometimes called lazy evaluation, short circuit evaluation or McCarthy evaluation. (John McCarthy was the creator of Lisp and is sometimes known as the father of artificial intelligence.)

When a function computes a value and caches the result, to produce it quickly in future without recomputing in case someone asks for the same inputs again, that is also sometimes referred to as lazy evaluation.


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/lazy.html J:\mindprod\jgloss\lazy.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.211]
You are visitor number 16,744.