5 ms·
Out of curiosity do you get a compiler warning when you use URL.equals?
by tuwtuwtuwtuw 7y ago
Out of curiosity do you get a compiler warning when you use URL.equals?
- ivan_gammel 7y agoNo and probably it will never happen in javac. Some IDEs may try to do static code analysis to identify possible uses of URL.equals (e.g. Map<? extends URL, ?>), but I doubt anyone would invest in this feature.
- matsemann 7y agoLooks like IntelliJ has it: - equals() or hashCode() called on java.net.URL object - Map or Set may contain java.net.URL objects https://www.jetbrains.com/help/idea/list-of-java-inspections.html https://www.jetbrains.com/help/idea/list-of-java-inspections...
- bspammer 7y agoDoesn't look like it's turned on by default though, which seems strange. Presumably if you care enough to go into the settings to enable that specific warning you're unlikely to make the mistake in the first place. It's exactly the type of non-obvious gotcha that would be nice to have your IDE warn you about out of the box.
- ShinTakuya 7y agoI agree and disagree. I mean, the thing is that outside of personal projects it's not uncommon to inherit a codebase from other people, sometimes quite a large codebase. Such a warning can be useful when eliminating boo-boos (acting as an lint I guess).
- tuwtuwtuwtuw 7y agoWouldn't you want warnings when an inherited code base does weird things with possible incorrect behaviors as side effect?
- ShinTakuya 7y agoWell I would consider DNS resolution on comparisons/hashing to be an incorrect behaviour as a side effect.
- ivan_gammel 7y agoIn this case Sonar will do a better job. IDE warnings are good for fixing them immediately - when they accumulate it’s very easy to stop paying any attention.