PROPOSAL: Abstract enums (version 2)

Howard Lovatt howard.lovatt at
Mon May 11 19:41:16 PDT 2009

Tom Hawtin wrote:
>> Yes a single element enum is a great singleton. Instead of:
> "Great singleton" is probably an oxymoron.

I find a limited set of instances, enums, useful and the singleton is
just the limit of that concept.

>> enum Singleton {
>>  // No INSTANCE
>>  void method() { ... }
>>  ...
>> }
> I think for grammatical reasons you'll need to retain the semicolon.

Can you expand on this, you are probably right if looked at the
grammar closely but I can't see where the problem is from a quick look
- I would be interested to know where the problem is.

>> Usage:
>> Singleton.method();
> If you add static to the method declaration, you are already there. Of couse still have the problem that you have introduced a load
> of inappropriate methods via enum.

I am wanting the enum to conform to an arbitrary, or at least near
arbitrary, interface and/or abstract class. Therefore these need to be
instance methods, not statics. As an aside, this is how Scala and
Fortress are able to deal with statics in a strictly OO manor by
having a singleton, which in the case of these two languages uses the
object keyword to make exactly one instance of the class. I am
proposing a similar solution for Java, but utilising an extension of
the enum construct.

You can't have a static and an instance method with the same
signature, therefore I don't think the call Singleton.method() will be
confusing to people or the compiler.

  -- Howard.

More information about the coin-dev mailing list