2 ms·
Java's == is not used for equality for objects either, so it's a valid comparison because Java's behaviour is equally unintuitive here. It's the same behaviour
by Macha 9y ago
Java's == is not used for equality for objects either, so it's a valid comparison because Java's behaviour is equally unintuitive here. It's the same behaviour as is for objects.
- bunderbunder 9y agoJava's behavior feels like an almost deliberate trap, though. I have previously lost hours to bugs resulting from a refactoring that changed a value's type from int to Integer, and the resulting change in equality semantics.
- mjevans 9y agoThat seems like such an anti-feature. I'd want the compiler to issue a warning for it by default and the IDE to ship with 'warnings are errors' by default.
- bunderbunder 9y agoInstead, we have some $$$$ static analysis tool that nags me endlessly about using Optional<T> private fields, but lets using the == operator for non-primitives sail past without comment.