Aug. 2nd, 2009

juan_gandhi: (Default)
Provide an alternate implementation of the following class (a thunk) that uses no conditional logic.
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();
}

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 9th, 2025 11:52 pm
Powered by Dreamwidth Studios