edu.rice.cs.plt.lambda
Class DelayedThunk<R>

java.lang.Object
  extended by edu.rice.cs.plt.lambda.DelayedThunk<R>
All Implemented Interfaces:
Box<R>, ResolvingThunk<R>, Thunk<R>, java.io.Serializable

public class DelayedThunk<R>
extends java.lang.Object
implements Box<R>, ResolvingThunk<R>, java.io.Serializable

A thunk whose value is set once after creation, but before the first invocation of value().

As a wrapper for arbitrary objects, instances of this class will serialize without error only if the wrapped object is serializable.

See Also:
Serialized Form

Constructor Summary
DelayedThunk()
           
 
Method Summary
 boolean isResolved()
          Test whether the thunk is in a "resolved" state.
static
<R> DelayedThunk<R>
make()
          Call the constructor (allows R to be inferred)
 void set(R val)
          Set the value.
 R value()
          Access the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelayedThunk

public DelayedThunk()
Method Detail

value

public R value()
Access the value.

Specified by:
value in interface Thunk<R>
Throws:
java.lang.IllegalStateException - if the value has not been set

set

public void set(R val)
Set the value.

Specified by:
set in interface Box<R>
Throws:
java.lang.IllegalStateException - if the value has already been set

isResolved

public boolean isResolved()
Description copied from interface: ResolvingThunk
Test whether the thunk is in a "resolved" state. If true, an invocation of value will return promptly and without exception.

Specified by:
isResolved in interface ResolvingThunk<R>

make

public static <R> DelayedThunk<R> make()
Call the constructor (allows R to be inferred)