title: Java Enums and Switch Statements - the default case?
body: <p>For people suggesting throwing an exception:<br>
  Throwing an exception doesn't give me a compile-time error, it gives me a runtime error. I know I can throw an exception, I'd rather die during compilation than during runtime.</p>
  
  <p>First-off, I am using eclipse 3.4.</p>
  
  <p>I have a data model that has a mode property that is an Enum.</p>
  
  <pre><code>enum Mode {on(...), off(...), standby(...); ...}
  </code></pre>
  
  <p>I am currently writing a view of this model and I have the code</p>
  
  <pre><code>...
  switch(model.getMode()) {
  case on:
     return getOnColor();
  case off:
     return getOffColor();
  case standby:
     return getStandbyColor();
  }
  ...
  </code></pre>
  
  <p>I am getting an error "This method must return a result of type java.awt.Color" because I have no default case and no return xxx at the end of the function.
  <strong>I <em>want</em> a compilation error in the case where someone adds another type to the enum (e.g. shuttingdown) so I don't want to put a default case that throws an AssertionError, as this will compile with a modified Mode and not be seen as an error until runtime.</strong></p>
  
  <p>My question is this:<br>
  Why does EclipseBuilder (and javac) not recognize that this switch covers all possibilities (or does it cover them?) and stop warning me about needing a return type. Is there a way I can do what I want without adding methods to Mode?</p>
  
  <p>Failing that, is there an option to warn/error on switch statements that don't cover all of the Enum's possible values?</p>
  
  <p>Edit: 
  Rob: It is a compile <em>error</em>. I just tried compiling it with javac and I get a "missing return statement" error targeting the last } of the method. Eclispe just places the error at the top of the method.</p>