PROPOSAL: Abstract enums (version 2)

Tim Peierls tim at peierls.net
Tue May 12 06:05:18 PDT 2009


I'm saying I am not in favor of a change to the Java language that would
make Foo.bar() a shorthand for something like Foo.$synthetic$.bar() when Foo
is an enum with no members. I think it would encourage people to write
confusing and hard to maintain code in exchange for the minor and doubtful
benefit of slightly more compact code. What if your singleton turned out not
to be a singleton? If you had implemented it as an enum with one member, no
problem: just add another member. If you had implemented it as an enum with
no members, you'd have to go back and change all uses of that enum.

--tim

On Tue, May 12, 2009 at 1:08 AM, Howard Lovatt <howard.lovatt at iee.org>wrote:

> Hi Tim,
>
> 2009/5/12 Tim Peierls <tim at peierls.net>:
> > It just doesn't seem worth the pain of a language change to me. If I were
> > ever really at a loss for a name for the singleton instance, I could go
> > minimal.
> > enum SingletonEnum {
> >     _;
> >     void method() { System.out.println("method called"); }
> >     public static void main(String... args) {
> >         SingletonEnum._.method();
> >     }
> > }
> > Or "THE", or "IT". But usually there's a natural name:
> > // Socratic singletons
> > enum Good { KNOWLEDGE; ... }
> > enum Evil { IGNORANCE; ... }
>
> I was probably in your camp until I started to use Scala and I found
> the object construct and the concept of a closed set of instances most
> useful. Since using a Scala a bit I think the construct is worth
> while. Have you used Scala or some other language with this construct?
>
>  -- Howard.
>



More information about the coin-dev mailing list