JDK-7127722 : Switch block for Class
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-01-06
  • Updated: 2012-03-20
  • Resolved: 2012-01-06
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
A natural extension of multicatch added in Java7 is the ability to switch() on Class instances. For example:

try
{
  future.get();
}
catch (InterruptedException | ExecutionException e)
{
  // Handle exception wrapped by ExecutionException
  switch (e.getCause().getClass())
  {
    case IOException.class:
    {
    }
    case IllegalArgumentException.class:
    {
    }
    // etc
  }
}

JUSTIFICATION :
Improved readability. The alternative is a long list of if/else "instanceof" statements.

Comments
EVALUATION Switching on a Class value can be accomplished by a using a string switch on the name of the class. Closing as will not fix.
06-01-2012