Bug 149562 - Small problem with enumerations and switch statements
Summary: Small problem with enumerations and switch statements
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-04 08:09 EDT by Michael Illgner CLA
Modified: 2006-07-28 08:58 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Illgner CLA 2006-07-04 08:09:02 EDT
Hi,
I've got the folling source code :

public class Test {  
  enum Types {One, Two;}

  public static void main(String[] args) {
    int val;
    Types type = Types.One;
    
    switch (type) {
    case One:
      val = 1;
      break;
    case Two:
      val = 2;
      break;
    }
    
    System.out.println(val);
  }
}

Eclipse complains that the variable val might not be initialized, but the switch/case statement covers all possible values of the enumeration.
Is this a bug ?
Comment 1 Philipe Mulet CLA 2006-07-04 08:13:58 EDT
Nope, this is the intentional behavior. You still need a 'default:' case for future evolutions (i.e. one could add another enum constant in the future, and unless you recompile your code, it may break some assumptions).

This behavior is described in the Java language specification.

maxime - pls make sure we have some regression test for it.
Comment 2 Maxime Daniel CLA 2006-07-28 08:58:08 EDT
Added EnumTest#test135.