webtier@glassfish.java.net

Re: [webtier] JSPs, Enums, and toString

From: Hilco Wijbenga <hilco.wijbenga_at_gmail.com>
Date: Wed, 7 Apr 2010 09:26:00 -0700

On 6 April 2010 15:09, <webtier_at_javadesktop.org> wrote:
> According to EL 2.2 spec, 1.18.2, when a Enum is coerced to a String, Enum.name() is used.  One may argue that toString() should be used instead, but the current behavior conforms to the spec.
> [Message sent by forum member 'kchung']

Wow, indeed, it says so in EL2.1 too. Thanks!

Mind you, this does not make sense to me. Without an explicit
toString(), Java uses the result of name() anyway. And name() can not
be overridden as it's final. So why not simply always use the default
Java behaviour and use toString()?

Using toString() is more intuitive (it's what a Java developer would
expect), simplifies the spec (fewer rules, no difference between Enums
and Objects), *and* it's much more flexible.

Do you remember why Enums are treated specially? (Given your user id,
I'm assuming you're Kin-Man Chung, one of the editors?) Is it too late
to change this?

Cheers,
Hilco