Re:Common I/O Tasks in Modern Java
by TheNightman on Friday August 02, 2024 @08:12PM
(#41143739)
No shot this is _ever_ what is actually meant by ‘if urlA == urlB’
Re:Common I/O Tasks in Modern Java
by hn_throwaway_99 on Friday August 02, 2024 @08:25PM
(#41143808)
Well, remember, this is Java, so `if (urlA == urlB)` just does standard object equality, the IP lookup is only done for `if (urlA.equals(urlB))` :)
It's still insane behavior. This implementation is effectively a sharp edge in the dark. Have fun.. :-/
This is Java, so you should always do `Object.equals(urlA, urlB)`, on the off-chance urlA is null!
(I do not miss working in Java haha)
Yes. 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.
https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#...