Non-collection literals [Re: JEP 186: Collection Literals]
Stephen Colebourne
scolebourne at joda.org
Sun Jan 19 00:14:12 PST 2014
I note that the JEP posted focuses only on collections, but there are
other types which would benefit from literals. Notably, this includes
date, time and quantity, but things like regex and URIs would also be
useful. I wanted to make two observations on that side.
1) String based literals are inefficient. For example:
. LocalDate.of(2014, 1, 19)
. LocalDate.of("2014-01-19")
The first is much more efficient than the second. However, the string
format is usually what the user wants as their literal.
2) Validation is important. It should not be possible to compile code
using an invalid date, regex or URI.
Given these, there must IMO be a processing step that does not simply
pass the literal into a method. eg. converting #[2012-06-30] to
LocalDate.of("2012-06-30") is not appropriate. Many of the builder or
string based approaches discussed in the other thread thus seem flawed
to me.
I'll avoid posting my syntax or design thoughts here at the moment.
Stephen
On 14 January 2014 00:17, <mark.reinhold at oracle.com> wrote:
> Posted: http://openjdk.java.net/jeps/186
>
> - Mark
>
More information about the lambda-dev
mailing list