Add a cast() method to Object

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P5
    • None
    • Affects Version/s: 7
    • Component/s: core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      Although generics have reduced the need for casting there are still occasions where you need to do it. A cast method that uses type argument inference would make casting much easier.

      So if this method existed in Object :

         @SuppressWarnings("unchecked")
         public <T> T cast()
         {
            return (T)this;
         }

      then most casts would be simplified to

      // very contrived example
      Object o = new MyType();

      MyType myObject = o.cast();

      instead of the current

      MyType myObject = (MyType)o;



      JUSTIFICATION :
      This means less code to type and read. That has to be good!

            Assignee:
            Joe Darcy
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: