Community
Participate
Working Groups
The following code results in an "Unnecessary Cast" being reported although removing the cast creates a compile error //--- import java.util.List; import java.util.function.Function; public class Test { <T extends Number> List<T> apply (Function<T, T> func) { return null; } <E> E identity(E a) { return a; } void test() { Integer i = apply (x -> identity((Integer)x)).get(0); } } //--- Created from bug 461706 comment 6.
Pasting relevant portions of the comment here > We still report as unnecessary (it is a cast Integer -> Integer!), but removing > the cast creates a compile error!! > > A fully precise analysis seems to require to rerun type inference with the cast > removed, because the cast may have been necessary to create the situation where > it is deemed unnecessary. > One solution would be to make a weaker warning "cast may be unnecessary", so > that UI can indeed trigger the rerun of inference to find out if it is really > unnecessary. The weaker form would be reported for any type that was "touched" > by type inference (not sure we can easily detect his, yet, but that's a > technical problem not a conceptual one). > > Or, UI could refuse to remove any casts inside a lambda, when running in cleanup > mode. >
*** Bug 466341 has been marked as a duplicate of this bug. ***
The cluster "unnecessary cast" calls for some action in 4.6.
Didn't get to it during 4.6, will take this up on priority for 4.7
Moving out of 4.7
Bulk move out of 4.9
Still happens in 2019-09 R (4.13.0) • JDT 3.18.100.v20190916-1045 • tried ecj 1.8, 12.
Sasi is no longer with the team. So, this one is up for grabs if anyone is interested.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.