Need warnings for extraneous casts

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: tools
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      "Unsafe" casts produce a warning.
      Generifying the class eliminates the warning, but can leave an extraneous cast that should be removed to improve readability. A warning would make it possible to determine which casts can safely be removed.

      JUSTIFICATION :
      Would help when converting legacy code to generics.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Rather than a lint option, this one should be a standard warning when you're using a parameterized type and the cast simply isn't needed.
      ACTUAL -
      No warning is delivered for an extraneous cast.

      ---------- BEGIN SOURCE ----------
      public class CastWarning {
        public void test() {
          List<Integer> numbers = new LinkedList<Integer>();
          numbers.add(1);
          Integer i = (Integer) numbers.get(0); // Should get a warning
        }
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: