quiz from an interview
Feb. 23rd, 2009 01:05 pmProvide an alternate implementation of the following class (a thunk) that uses no conditional logic.
For extra credit, make it thread-safe.
Your solutions welcome.
For extra credit, make it thread-safe.
abstract class Thunk<T> {
private boolean evaluated = false;
private T value;
public T get() {
if (!evaluated) {
value = compute();
evaluated = true;
}
return value;
}
abstract protected T compute();
}
Your solutions welcome.