velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: Handling of primitive type arrays
Date Wed, 18 Apr 2012 18:08:13 GMT
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.polet@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-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>

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


Mime
View raw message