velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daryl Beattie" <>
Subject RE: Re: Problem getting value from Map.
Date Fri, 06 Oct 2006 21:51:39 GMT
Hi Henning,

	In the original code, the toString() for Name was:

public String toString() {
  return name;

	So new Name("a").toString() does = "a".
	Also, the toString() doesn't have an effect upon $bo.get("a"),
because the get(Object key) method uses the "a" string literal as a
parameter to the constructor of Name. It is only the hashCode() of two
separate Name("a") instances that must be equal for $bo.get("a") to
work; and I did override .hashCode() in Name as well. So everything
*should* work... I can't figure out why it does not.
	In fact, getA() isn't necessary for this example at all; it can
be removed altogether and $bo.get("a") still does not work. I only
included getA() to show that OTHER velocity method resolutions work in
the very same template, but that the one I need does not work.
	My guess is that the code inside Velocity that figures out which
method to call isn't resolving the method properly according to the Java
standard way of doing it. So it's probably calling the wrong get()
method or something. If somebody could point me to the section of the
Velocity code that figures out which method to call, I could probably
diagnose the issue (though it's a long weekend this weekend, so maybe
next week).
	Any thoughts?



-----Original Message-----
From: Henning P. Schmiedehausen [] 
Sent: Friday, October 06, 2006 4:21 PM
Subject: Re: Problem getting value from Map.

"Daryl Beattie" <> writes:

>class DataHolder extends HashMap<Name, Value> {

>  public Value getA() {
>    return this.get(new Name("a")); //$NON-NLS-1$
>  }

>  @Override
>  public Value get(Object key) {
>    return super.get(new Name(key.toString()));
>  }

Quick question: Shouldn't that be

public Value getA() {
  return super.get(new Name("a")); //$NON-NLS-1$

In your case, calling getA() ends up being

super.get(new Name(new Name("a").toString()));

If new Name("a").toString() != "a", then it is understandable why
$bo.A works and $bo.get("a") not.

	Best regards

Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH        +49 9131 50 654 0

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for
   Linux, Java, perl, Solaris -- Consulting, Training, Development

Social behaviour: Bavarians can be extremely egalitarian and folksy.
Most Franconians do not like to be called Bavarians.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message