9 ms·
When you do equality checks on two URL instances, it checks to see if they resolve to the same IP address by hitting up DNS. This is problematic because equalit
by yen223 2y ago
When you do equality checks on two URL instances, it checks to see if they resolve to the same IP address by hitting up DNS. This is problematic because equality checks happen implicitly all the time, e.g. if you're putting URLs into a hashtable.
https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#equals-java.lang.Object- https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#...
- TheNightman 2y agoNo shot this is _ever_ what is actually meant by ‘if urlA == urlB’
- hn_throwaway_99 2y agoWell, remember, this is Java, so `if (urlA == urlB)` just does standard object equality, the IP lookup is only done for `if (urlA.equals(urlB))` :)
- layer8 2y agoYes. Use the newer URI class instead if you want a value object without “smarts”. URL instances also contain a URLStreamHandler, which means that two URL instances that compare equal can still have different URLStreamHandlers that handle the URL differently. Instances of the class URL are really service objects.