4 ms·
I have never came up to a code that would pass null in place of Optional, why?
by krzyk 4y ago
I have never came up to a code that would pass null in place of Optional, why?
- ender341341 4y agoBecause you don't always control where the code is being called from. Other compile time typed languages (C, C++, C#, typescript, rust, kotlin) usually would let you enforce that as part of the type system, but the java compiler will silently accept null in place of optional and throw an NPE at runtime.
- mohaine 4y agoPretty much every JSON parser in java does this by default. Why? Because they were all written before Optional existed. I have to agree with the Optional hate. I loved it in Scala but after a few months on Kotlin I don't think I can go back.
- krzyk 4y agoJackson does it well. Any sane json library has to support newer Java idioms, if not it is not worth using.