Is it an immutable that the getValue returns the same value for the
entire lifetime of the object? else we have the added problem of
invalidating the cached value etc...
what is interesting about your example code is that you use a boolean
and not a compare to null like
private value = null;
public String getValue()
{
if (!(value == null))
{
try
{
value = ByteUtils.toString(getStream());
}
catch (IOException ioe)
{
}
}
return value;
}
Any specific reason why you did that ? One could be that the value
can have a legit null value for its entire lifetime .. but that is
kinda hard to imagine...
On 11/3/06, Vincent <[EMAIL PROTECTED]> wrote:
Jerome,
> Agreed, let's reuse the safer "getValue() : String" method introduced in
> StringRepresentation and deprecate toString().
Thanks for making the change.
Why not go one steo further and have getValue cache the value?
private boolean cached = false;
private value = null;
public String getValue()
{
if (!cached)
{
try
{
value = ByteUtils.toString(getStream());
cached = true;
}
catch (IOException ioe)
{
}
}
return value;
}
This way getValue, Request.getEntityAsString, etc. would always return the same
result. Which is what you expect from a method with a getter-like name, and
would prevent some hard-to-pinpoint bugs.
-Vincent.