On Mon, Feb 6, 2017 at 7:48 AM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> Claude,

...

> > $obj returns false from getAsBoolean() (provided there is such a method)
>
> $obj is empty string (CharSequence w/length 0)
> > $obj returns true from isEmpty() (provided there is such a method)
> > $obj is array of length 0
> > $obj returns null from getAsNumber() (provided there is such a method)
> > $obj returns 0 from length() or size() (provided there is such a method)
> > $obj returns empty string from toString() (provided there is such a
> method)
> >
> > Also, I noticed that Velocity weren't very consistent with literals. The
> > only literal returning true is the 'true' literal. "foo" is false,
> > whereas it should be consistent with $foo containing "foo".
>
> Can we maybe make an exception for Collections? Maybe for a Collection
> (or array), we never call toString() on it? [].toString will always give
> you garbage (which will be truthy) and Collection.toString() will also
> likely give you garbage and it will also always be truthy unless it's
> (a) null or (b) the Collection implements toString in a surprising way
> relative to java.util Collections.
>
...

Yeah, one of the crucial ideas here is that Velocity would stop checking as
soon as it found one of these. So no Array, CharSequence, or Collection
would ever make it down the lookup chain to toString(). The goal is to be
more type/function aware specifically to avoid getting down to the
toString(), but still leaving that toString() check for better backward
compatibility.

Reply via email to