Re: Enum, switch, and a null
On Sep 1, 5:33 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
On Tue, 28 Aug 2007 17:41:11 -0700, Daniel Pitts
<googlegrou...@coloraura.com> wrote, quoted or indirectly quoted
someone who said :
So, if you add a new enum value, you don't have to update all of the
switch statements in 100 places?
On the other paw, you at least can see how you handled all the other
enums when you write this code. You are more likely to get each one
correct even if you are likely to forget one.
What happens if you leave off default with enums? Is the compiler
smart enough to warn you if you leave out an enum? Is it smart enough
not to complain if you do provide them all?
In a SCID I suggest you should be able to transform your code so you
can see it comparing how all enums implemented a method, and how a
given enum implemented all its method. My studying the code from both
views you are more likely to get is right.
Seehttp://mindprod.com/jgloss/project/scid.html
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com
The compiler may issue a warning if your switch doesn't have the enum
branches.
The compiler WILL issue an ERROR if you don't implement an abstract
method in a concrete class.
If you need to study all other implementations in order to get your
implementation correct, that seems to me to be a bad design. The
infrastructure should take care of all the complicated bits, and just
ask the polymorphic class to handle the differing details.