On 12/08/2011 22:43, Kin-man Chung wrote:
> I'd like to consider adding constructors in EL. We now can call
> arbitrary methods (including static methods) with arguments in EL
> expressions; so it seems natural that we should add constructor calls,
> as we have all the syntactic elements already.
Just because we can, doesn't mean we should. The more syntax we add, the
more complicated EL gets for users yet EL is mean to make things simpler.
If there isn't a clear use case for a new feature, I don't think we
should add it. To quote from the proposal:
"... it is not the intention of this specification to turn EL into a
general language and the original goal to keep it simple and easy to use
will be followed."
> If we are to follow the Java syntax, such as 'new
> com.acme.Sale("Europe")', we'll need to add "new" as a reserved word.
> I think in the EL context, "new" is unnecessary, and can be omitted
> without real problem. So here's the proposal.
>
> Constructor Syntax:
>
> T(<className>)(args)
>
> such as #{T(com.acme.Sale)("Europe")}.
>
> WDYT?
If we go this route - and at the moment I don't think we should - there
also needs to be a way of assigning an identifier to the new object so
it can be referred to later. There isn't much point being able to create
a new object if you can't do anything with it.
> I am less sure about adding constructors for arrays, as it'd add more
> reserved words (e.g. primitive types) and complexities to the syntax.
> And I'm not convinced of its usefulness. So this is a still a maybe.
> Possible syntax:
>
> int[]{1,2,3}
> T(java.lang.Object)[]{"string", T(com.acme.Sale)("Europe")}
The more I look at this, the more I think "If the user wants to do that
they should use Java rather than EL".
> Further down the priority list is adding functionalities for
> constructing collection objects. We may come back to this later when we
> deal with collections, if we ever get to that.
There are other features that have been requested that have not yet been
addressed. Maybe we would be better spending time working on those?
Mark