This interface is an abstract base for fields and similar
objects. It doesn't define many methods, it mainly indicates, that
the implementations value is directly and fast accessible in
the generated code. The use is best demonstrated by an example.
Suggest the following piece of code:
Object value;
return new Object[]{"((", value, ") * (", value, "))"};
The example is well suited for the case, where
value
is a variable name like "i". It is not suited, if "value" contains
an expensive method call like "sin(x)". It is even wrong in the
case "i++".
By using the interface
DirectAccessible
, you can
change the implementation of
getSquare()
to look
like this:
Object value;
JavaQName type;
if (!(value instanceof DirectAccessible)) {
LocalJavaField v = pMethod.newJavaField(type);
v.addLine(value);
v.setFinal(true);
value = v;
}
return new Object[]{"((", value, ") * (", value, "))"};
This results in code, which is far more readable and better
optimized.