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 ----------
"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 ----------
- duplicates
-
JDK-6227617 Lint option for redundant casts
- Closed