Re: Varargs
Brian Pontarelli <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Aug 3, 2011, at 2:07 AM, Daniel Dekany wrote:
> Tuesday, August 2, 2011, 9:20:43 PM, Brian Pontarelli wrote:
>
>> I've read that vararg method calls were added to 2.4.12 but I can't
>> find any good docs on how to use them and if there are any special
>> requirements. I have a varargs method that I'm trying to invoke from
>> a template and I'm getting an argument type mismatch exception:
>>
>> public boolean hasRoles(String... roles) {
>> ...
>> }
>>
>>
>> [#if user.hasRoles(["foo", "bar"])]
>> …
>> [/#if]
>>
>> Anyone know how to fix this?
>
> AFAR it's supposed to Just Work (assuming you are using some
> BeansWrapper subclass as the object_wrapper setting, and it's 99% that
> you do). Have you tried user.hasRoles("foo", "bar"), without the []?
Yeah, tried that. It then complains about trying to convert String to String[]. I do have a BeansWrapper sub-class, but all it does is set these two options:
setExposeFields(true);
setSimpleMapWrapper(true);
Not sure how to fix it, but I changed the method to take an Iterable<String> and it is working.
-bp
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1