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

Need warnings for extraneous casts

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • 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 ----------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: