You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2008/03/10 21:12:30 UTC
Choosing the right method on an object
All,
This is a bit more of a "users" list question, but I think it will
evolve into a dev discussion, so I'm posting it here.
I have a List that I'd like to remove objects from. java.util.List
implements two "remove" methods: one that accepts an (int) index into
the list and one that accepts a list element (java.lang.Object).
My list elements are java.lang.Integer objects, so in the eyes of
Velocity, there is an ambiguity, here. Velocity happens to pick
remove(int) when I'd prefer remove(Object) in my case.
Is there a way to force Velocity to pick a particular version of a
method? In Java, you'd just cast the object to a particular class to
remove any ambiguity, but that option is not available for Velocity.
Any suggestions?
-chris
Re: Choosing the right method on an object
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Nathan,
Nathan Bubna wrote:
> On Mon, Mar 10, 2008 at 1:12 PM, Christopher Schultz
>> My list elements are java.lang.Integer objects, so in the eyes of
>> Velocity, there is an ambiguity, here.
>
> eek.
Yeah. :(
>
>> Velocity happens to pick
>> remove(int) when I'd prefer remove(Object) in my case.
>
> but would you prefer that in general? i'm guessing not. i think
> Velocity is doing the right thing here and suspect you'd agree.
I do agree, and wasn't really suggesting that Velocity should act any
differently (in this case). I was just wondering if...
>> Is there a way to force Velocity to pick a particular version of a
>> method? In Java, you'd just cast the object to a particular class to
>> remove any ambiguity, but that option is not available for Velocity.
>
> no, and i can't think of any easy way to do it with adding syntax for
> casting or making it so the Uberspect does the "generally wrong" thing
> here. and i think i'd oppose either of those, the first on grounds of
> barely useful complication and the latter because it would be
> backwards incompatible and i think not fit the general use-case. i
> suppose you could hack up a custom Uberspect or Introspector that
> watches for this special case and use that for your application, but
> that seems ugly.
Yup, I completely agree. In some respects, this is really a problem with
the List API itself because the overloaded remove method has two
different semantics. This is quite a special case, really.
>> Any suggestions?
>
> i'd suggesting looking for another way to have your template do as you
> wish. removeAll(Collection)? a tool? something else entirely?
Instead of $myList.remove($myInt), I did use
$myList.removeAll([$myInt]), which satisfied my needs. I was just
looking for a possibly more elegant solution.
-chris
Re: Choosing the right method on an object
Posted by Nathan Bubna <nb...@gmail.com>.
On Mon, Mar 10, 2008 at 1:12 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> All,
>
> This is a bit more of a "users" list question, but I think it will
> evolve into a dev discussion, so I'm posting it here.
>
> I have a List that I'd like to remove objects from. java.util.List
> implements two "remove" methods: one that accepts an (int) index into
> the list and one that accepts a list element (java.lang.Object).
>
> My list elements are java.lang.Integer objects, so in the eyes of
> Velocity, there is an ambiguity, here.
eek.
> Velocity happens to pick
> remove(int) when I'd prefer remove(Object) in my case.
but would you prefer that in general? i'm guessing not. i think
Velocity is doing the right thing here and suspect you'd agree.
> Is there a way to force Velocity to pick a particular version of a
> method? In Java, you'd just cast the object to a particular class to
> remove any ambiguity, but that option is not available for Velocity.
no, and i can't think of any easy way to do it with adding syntax for
casting or making it so the Uberspect does the "generally wrong" thing
here. and i think i'd oppose either of those, the first on grounds of
barely useful complication and the latter because it would be
backwards incompatible and i think not fit the general use-case. i
suppose you could hack up a custom Uberspect or Introspector that
watches for this special case and use that for your application, but
that seems ugly.
> Any suggestions?
i'd suggesting looking for another way to have your template do as you
wish. removeAll(Collection)? a tool? something else entirely?
> -chris
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org