public class ArrayTool {
   public long[] toLongs(List<Number> nums)
    {
        long[] arr = new long[nums.length];
        for (int i=0; i<nums.length; i++)
        {
            if (nums[i] != null)
            {
                arr[i] = nums.get(i).longValue();
            }
        }
        return arr;
    }
}

context.put("array", new ArrayTool());

and so on...

or anything like that.

On Wed, Apr 18, 2012 at 10:51 AM, Guillaume Polet
<guillaume.po...@gmail.com> wrote:
> Hi list,
>
> I was wondering how arrays of primitives are handled in Velocity. I feel
> that they are converted to List<> and then we cannot invoke methods with
> them as parameters.
>
> Let's take an example:
>
> #set($array = [$ref.getLong(), $ref.getLong(), $ref.getLong()] # where
> $ref.getLong() returns a long (primitive type)

Velocity cannot create the $array value to be an actual array.

> #ref.invokeSomeMethod($array) # where the signature is actually public void
> invokeSomeMethod(long[] values)
>
> How can I get this to work?
>
> Cheers,
> Guillaume
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
> For additional commands, e-mail: user-h...@velocity.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org

Reply via email to