MemorizedCallable implements Callable<V> { MemorizedCallable(final Callable<V> callable) { this.callable = callable; value = (V) NOTHING; } MemorizedCallable(final Callable<V> callable); @Override V call(); V clear(); NullAbleOptional<V> getIfMemorized(); void set(final V v); @Override String toString();  }
@Test public void testMemorizedCallable() throws Exception { MemorizedCallable<String> mc = new MemorizedCallable(new Callable() { private int i = 0; @Override public Object call() { return "val" + (i++); } }); Assert.assertEquals("val0", mc.call()); Assert.assertEquals("val0", mc.call()); mc.clear(); Assert.assertEquals("val1", mc.call()); }