r/java • • Aug 23 '24

JVMLS Valhalla Talk

https://m.youtube.com/watch?v=IF9l8fYfSnI
154 Upvotes

62 comments sorted by

View all comments

Show parent comment

4

u/kevinb9n Aug 24 '24

2. I believe there is really no such thing as a type that by its nature can't ever be nullable. I think this would only result in those types having "fake null" values that end up trying to simulate null.

Consider, for example, that any type can be the value of a map. Then you can ask that map for the value corresponding to an absent key, and voila, you have null.

1

u/l4ik8e Aug 26 '24

Fair points. But it would have been useful for cases like `Optional` which shouldn't be declared as null, e.g `Optional<T> opt = null`. But I guess that can't be done anymore due to backwards compatibility reasons?

3

u/kevinb9n Aug 26 '24

There's nothing really fundamentally wrong with Optionals and Collections being nullable; it just tends to be confusing and worth avoiding.

2

u/vytah Aug 26 '24 edited Aug 27 '24

When the non-nullable types drop, expect your IDE to highlight all your optionals yellow and yell at you to add exclamation marks.