Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4032356

Java needs a typecase-like statement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1, 6
    • specification
    • None
    • generic, x86, sparc
    • generic, solaris_2.5.1, windows_nt



      Name: mc57594 Date: 02/13/97


      I often find myself writing code that looks like this:

      void blah (Object x)
      {
          if (x instanceof ClassOne)
          {
              ClassOne x1 = (ClassOne) x;
              ...;
          }
          else if (x instanceof ClassTwo)
          {
              ClassTwo x2 = (ClassTwo) x;
              ...;
          }
          ...;
      }

      It'd sure be nice if Java offered a typecase-like statement,
      especially since it already has it for exceptions! The above could
      look something like this:

      void blah (Object x)
      {
          typeswitch (x)
          {
              case ClassOne x1:
              {
                  ...;
                  break;
              }
              case ClassTwo x2:
              {
                  ...;
                  break;
              }
              ...;
          }
      }

      company - Electric Communities , email - ###@###.###
      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: