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

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23242526272829
30      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 21st, 2025 09:48 am
Powered by Dreamwidth Studios