Because what you meant was that you don't want to lose information about
parameter *names*. Fair enough.
Yes, you are correct. I would like to have a full automatic routine to
collect *names* and values of all arguments passed to my method.
In particular: after adding another parameter to my method I don't
want to remember, that I must add this parameter to all exception
messages.
I like to automatize things which are the same for most cases. For
example, in my Java project, I automatized toString method. For almost
all my classes, toString method is just a one line of code:
@Override public String toString()
{
return ToStringBuilder.objectToStringInOneLine(this);
}
.... where ToStringBuilder class is a static util class using
org.apache.commons.lang.builder.ReflectionToStringBuilder:
public class ToStringBuilder
{
public static String objectToStringInOneLine(final Object obj)
{
final String str = ToStringBuilder.objectToString(obj,
ToStringStyle.SHORT_PREFIX_STYLE);
return str;
}
public static String objectToString(final Object obj, final
ToStringStyle toStringStyle)
{
return doObjectToString(obj, null, toStringStyle);
}
// ...
private static String doObjectToString(
final Object obj
, final String[] excludeFieldNamesParam // can be null.
, final ToStringStyle toStringStyle
)
{
final ReflectionToStringBuilder rtsb =
new ReflectionToStringBuilder(obj, toStringStyle)
{ /* empty block */ };
if(excludeFieldNamesParam != null)
rtsb.setExcludeFieldNames(excludeFieldNamesParam);
return rtsb.toString();
}
}
Of course there *must* be a way to obtain arguments names and their
(runtime) values because all Java debuggers can *see* those things
when I'm standing on a breakpoint in Debug mode.
Thanks!
Adam Wozniak