Hi Henning,

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

@Override
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?

Sincerely,

        Daryl.


-----Original Message-----
From: Henning P. Schmiedehausen [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 06, 2006 4:21 PM
To: velocity-user@jakarta.apache.org
Subject: Re: Problem getting value from Map.

"Daryl Beattie" <[EMAIL PROTECTED]> 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
                Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
[EMAIL PROTECTED]        +49 9131 50 654 0   http://www.intermeta.de/

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

Social behaviour: Bavarians can be extremely egalitarian and folksy.
                                    --
http://en.wikipedia.org/wiki/Bavaria
Most Franconians do not like to be called Bavarians.
                                    --
http://en.wikipedia.org/wiki/Franconia

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to