jsr341-experts@el-spec.java.net

[jsr341-experts] Constructors in EL

From: Kin-man Chung <kinman.chung_at_oracle.com>
Date: Fri, 12 Aug 2011 14:43:58 -0700

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.

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?

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")}

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.

Kin-man