Java needs a typecase-like statement

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 1.1, 6
    • Component/s: 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 - ###@###.###
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: