4 ms·
NullAway with JSpecify annotations are a really good way to add null safety to Java applications. Even enforces nullability at the generic level.
by retrodaredevil 12d ago
NullAway with JSpecify annotations are a really good way to add null safety to Java applications. Even enforces nullability at the generic level.
- rendaw 12d agoThe elephant in the room is the standard library (collections). It isn't even type safe yet, because some methods were around before generics were added. And collections are too core for anyone to be able to agree on a 3rd party standard.
- retrodaredevil 11d agoI mean, I guess you could say stuff like get(Object) and contains(Object) aren't type safe, but I've never seen that as an issue in practice. Plus there are some ErrorProne checks that'll tell you if you're doing something wrong in regards to calling contains(Object) with the wrong type.
- vbezhenar 10d agoThey accept Object not because they're not type safe. They accept Object because key `equals` method might return `true` for unrelated classes by design, and collections interfaces have to accommodate for that. In other words, you might put key of class C1 into the map, and later use `get` with key of class C2. And if these classes happen to implement `equals` accepting each other, the collections are supposed to work. So the core issue is that `Object.equals` method isn't type safe. Collections API just follow that.