> Is it an immutable that the getValue returns the same value for the
> entire lifetime of the object?
I would tend to say 'yes'.
> else we have the added problem of
> invalidating the cached value etc...
Sure, if we have a setValue method (or any method that affects the value), it
should reset the cache. Why is that a problem?
> what is interesting about your example code is that you use a boolean
> and not a compare to null like
> Any specific reason why you did that ?
two reasons:
1) in case -as you suggested- null is a valid value (like you,I cannot think of
a good use-case, but you never know).
2) to deal with the exception. Right now the IOE is swallowed, but I imagine
Jerome will want to fix that before 1.0 goes final.
So we could have something like:
private boolean cached = false;
private value = null;
private RuntimeException rte = null;
public String getValue()
{
if (!cached)
{
try
{
value = ByteUtils.toString(getStream());
cached = true;
}
catch (IOException ioe)
{
rte = new IllegalStateException();
}
}
if (rte != null)
{
throw rte;
}
return value;
}
Just think aloud here.
-Vincent