You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Winson Quock <wq...@cplane.com> on 2002/11/11 20:48:04 UTC

Fail to call overloaded methods in foreach loop

Hello,

I have reported a bug

http://issues.apache.org/bugzilla/show_bug.cgi?id=13637

but has not seen any update to it. I would like to see if there is any
workaround than to make all my overloaded method private and to create public
one that takes generic class as arguments.

Or if this will be fixed soon.

Thanks.

--- the bur reported ---

1 create a class with two overloaded methods like
public class Helper {
   public String getFoo(Integer v) { return "int "+v; }
   public String getFoo(String v) { return "str "+v; }
}
2. put an instance of Helper and a collection containing two items of
different types
col = new ArrayList();
col.add(new Integer(100));
col.add("STRVALUE");
ctx.put("helper", new Helper());
ctx.put("col", col);
3. in a template, do
#foreach ( $item in $col )
${helper.getFoo($item)
#end
4. evaluate the template and you should see
int 100
${helper.getFoo($item)

The error: the second item should invoke getFoo(String) but it apparently
fails and causing the invocation failure.

-------------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>