• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

enums & abstract modifier

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

probably one of you may answer me a question.
I'm reading: http://jcp.org/aboutJava/communityprocess/jsr/tiger/enum.html

There you may read, that enum declarations may NOT use the class modifier abstract, unless they contain constant specific class bodies for every enum constant......

In my opinion I have implemented exactly that:


===> Well, if you try to compile this enum, it works. No problem at all.
BUT: try to declare the enum Place as abstract (since it contains an abstract method) and you'll get a compiler error (...at least within my Netbeans 4.0).

I'm still wondering...; well, let's try the plain javac .....we will see

regards
marco
[ February 05, 2005: Message edited by: Jim Yingst ]
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tiger doesn't support enums hierarchy --> an enum is effectively final. But since value-specific methods through anonymous inner classes will be bowerfull, it allows this special type of subclassing --> it allows abstract methods, yet the enum itself still final (can't be subclassed) --> can't be declared abstract (nor final!).
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marco, I edited your post above to include [code] tags - this preserves the indentation in your code, making it more readable.

Note that the page at jcp.org is part of the earlier documentation for what was, at the time, a proposed new language feature. Now, enums are an actual existing language feature - but the way they work has been modified a bit since the initial proposal. You're looking at old documentation. A better reference now is at

http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

Basically, Sun decided (correctly, I think) tht it didn't make any sense for the enum itself to be declared abstract, since it's impossible for any code outside the enum to extend it. Only the method is abstract, and only code within the enum declaration is capable of overriding it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic