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

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 17th, 2025 10:12 pm
Powered by Dreamwidth Studios