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 9 10 111213
14 151617 181920
212223 24252627
28 2930    

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 30th, 2025 08:29 am
Powered by Dreamwidth Studios