4 ms·
This seems like incredibly bad design. Is there any justification or use case where someone would want the abstraction to leak like this?
by auntienomen 2y ago
This seems like incredibly bad design. Is there any justification or use case where someone would want the abstraction to leak like this?
- cowanon55 2y agoIt is likely because equals is usually “object equals”, not necessarily “math equals”. Since the internal representation is different, the objects are indeed different. Tricky though, and most 3rd party code would likely choose to make equals true in this kind of situation. Java has tons of examples where the core behavior is logically correct, but VERY unintuitive - I feel the pain daily.
- ktm5j 2y agoI don't think that flies, because the whole point of the .equals() method in regards to string is to avoid "object equals" and make sure the strings say the same thing..
- Tao3300 2y agoIt's supposed to be a mess. We have very little job security anymore.
- erik_seaberg 2y agoIf one mass is 1.0 kg ± 40 g, and another mass is 1.000 kg ± 0.4 g, are they close enough to equal? Maybe, and if you round them to the same precision you get whichever answer you wanted.
- jjmarr 2y agohttps://en.wikipedia.org/wiki/Significant_figures https://en.wikipedia.org/wiki/Significant_figures Trailing zeroes convey information about the measurement precision of a number. If you're doing math with real-world measurements, errors accumulate, and you're expected to keep track of them.
- auntienomen 2y agoAll true, but using a BigDecimal to do that is abusing the implementation and keeping important assumptions implicit. Better to explicitly quantify the uncertainty with a second variable.
- taspeotis 2y agoEh just par for the course for Java https://news.ycombinator.com/item?id=21765788 https://news.ycombinator.com/item?id=21765788