| ▲ | parallax_error 3 days ago | ||||||||||||||||||||||||||||||||||||||||
Really cool, shame that strings can’t be fully indistinguishable like Integer despite their immutability | |||||||||||||||||||||||||||||||||||||||||
| ▲ | nogridbag 2 days ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||
One misconception I had was that with value objects we could simply use `==` for comparison. But it looks like there's lots of gotchas with this especially if the value class has String fields for one or more fields. For example, comparing two ZonedDateTime value objects may be fine with == because I believe the JDK team ensured the Strings that represent the ZoneIds are always the same reference. We have tons of wrapper classes in our codebase which seem ideal as value objects. For example, instead of passing around "String emailAddress", we have a wrapper class EmailAddress. While we can now make our EmailAddress class a value object, we cannot do "==". Unlike ZoneId in which there's a fixed set and you can intern all ZoneIds in the string pool, email addresses are unique and trying to intern all email addresses would be a bad idea. So it seems like using .equals is here to stay even for these types of basic classes. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | cogman10 3 days ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
I don't think there's a lot of gains to be had for strings. Perhaps if you are dealing with a very large amount of small strings then it could be useful, but once you get past a few characters strings it's faster to just send around a reference anyways. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | fallingbananna 3 days ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||
Is there a theoretical reason why they can’t? As a layman I would assume nothing is preventing it, other than the large amount of effort it would take to implement. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||