Reputation: 13
Is there a setting in Eclipse Luna (or a newer version) that enables a warning to be displayed in the following case:
Map<K, V> map = new HashMap<>();
map.get(val);
where the type of val is not K? (the warning should be displayed on the second line)
I know that the code above is valid because Map.get takes an Object as an argument, but in almost every case is an error on my part, so I would like a warning to be displayed.
Upvotes: 1
Views: 225
Reputation: 9635
IntelliJ Idea will give you a Warning as part of their static code analysis. In eclipse, you can install FindBugs from the marketplace and although that check doesn't come out of the box, you can implement your own bug Detector. Check this out
Upvotes: 0
Reputation: 72854
Eclipse and its compiler are meant to be aligned with the Java compiler and the formal language specification. The javac
compiler accepts your code without any warning (even with -Xlint
enabled), because the get
method takes an Object
.
So there is no reason why Eclipse should come up with its own warning. Seems more like the job of a static analysis tool like FindBugs.
Upvotes: 2