Created
September 19, 2012 23:42
-
-
Save yonatanm/3753060 to your computer and use it in GitHub Desktop.
a Thunk Quiz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Thunk<T> { | |
private boolean evaluated; | |
private T value; | |
public T get() { | |
if (!evaluated) { | |
value = compute(); | |
evaluated = true; | |
} | |
return value; | |
} | |
abstract protected T compute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provide an alternate implementation of the following class (a Thunk - http://en.wikipedia.org/wiki/Thunk_%28functional_programming%29) that uses no conditional logic. For extra credit, make it thread-safe.
send your CV to [email protected]