aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Weird enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Weird enum" Watch "Weird enum" New topic
Author

Weird enum

Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
I'm surprised a constant specific class body may define a method not matching anything in the enum body itself:



Bug or feature?
[ October 08, 2006: Message edited by: Ade Barkah ]

-Ade<br /><a href="http://www.barkah.org" target="_blank" rel="nofollow">www.barkah.org</a>
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Bug or feature?
Anyway, the example reminds me to anonymous classes with new methods that can never be invoked, as



Bu.


all events occur in real time
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
Well, technically in either case the methods can be invoked via reflection.



(Enum version analogous).

The problem with the enum case is typically we want to create a special version of a method declared in the enum body:



Notice GREEN's version has incorrect spelling, and the wrong method will be called for GREEN without any warning.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I don't think this is a deficiency of the enum concept. An enum is just basically a special instance of a class.

The example you cited could easily happen when a programmer accidentally misspells an inherited method when they mean to override it.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
We're beyond the scope of SCJP certification here. To discuss the merits or disavantage of enum features and using reflection please use one of our Java In General (Intermediate) or (Advanced) forums. Moving to JIG(Intermediate)...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird enum