Interface Environment<K,V>

All Superinterfaces:
Map<K,V>
All Known Implementing Classes:
HashEnvironment, PersistentEnvironment

public interface Environment<K,V> extends Map<K,V>
An Environment is a Map with scoping: you can save marks into the environment and undo all changes since a mark.

Closing a mark undoes all changes since the mark, so a try-with-resources statement makes a scope:

 try (Environment.Mark scope = env.getMark()) {
     env.put("x", 1); // the binding of x until the end of the block
     ...
 } // x has its old binding, or none, again
 
(javac -Xlint:try warns that scope is not used in the block; Java 22 and later can name it _ instead.)
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
  • Method Details