All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----epp.Dynamic
Dynamic
class provides the same mechanism as the lisp
dynamic variable.
Dynamic variables are similar to global variables except that their scope are dynamic.
The bind
method saves old values to the stack and then
modifies the actual value.
The unbind
method retrieves values from the stack and
restores the original values of the variables last bound.
Subclasses of type Object
are the only values you can assign
to a dynamic variable. Dynamic variables are initially in an unbound state.
If you try to set/get a value when in this state, an
UnboundDynamicVariableAccessException
will be thrown.
You would frequently want to wrap an int type with an Integer
class and assign it to a dynamic variable. The methods bindInt
,
getInt
, and setInt
are provided for this purpose.
If you use these methods, arguments and return values will be
wrapped/unwrapped automatically with the Integer
class.
(Future versions will save int types and Object
types
in separate locations.)
Example ------- void foo(){ ...; Dynamic.bind(:sym1, val1); Dynamic.bind(:sym2, val2); try { // Do try immediatly after bind. ...; bar(); ...; return; } finally { // Do unbind the same number of times as you did bind. Dynamic.unbind(); Dynamic.unbind(); } } void bar(){ Object val = Dynamic.get(:sym1); Dynamic.set(:sym2, val); }
var
to value val
.
var
to value
new Integer(val)
.
var
.
var
.
var
to
val
.
var
to
new Integer(val)
.
bind
method.
public Dynamic()
public static void bind(Symbol var, Object val)
var
to value val
.
The old value of the dynamic variable var
is saved in
another place.
public static void bindInt(Symbol var, int val)
var
to value
new Integer(val)
.
The old value of the dynamic variable var
is saved in
another place.
public static void unbind()
bind
method.
public static Object get(Symbol var)
var
.
public static int getInt(Symbol var)
var
.
To be precise, the method does the same thing as the following.
((Integer)Dynamic.get(var)).intValue()
public static void set(Symbol var, Object val)
var
to
val
.
Unlike the bind
method, the old value is not saved.
public static void setInt(Symbol var, int val)
var
to
new Integer(val)
.
Unlike the bindInt
method, the old value is not saved.
All Packages Class Hierarchy This Package Previous Next Index