I'm currently in the process of switching over from java to kotlin and one of the stated advantages that keeps popping up is that kotlin is Null safe and by default cant have variables or objects be assigned a null value but there are ways to assign a null value. However I'm not sure why this is beneficial what problems arise from Java not being null safe?
Thus far online searches have only yielded descriptions of what null safety is and not why it was implemented. Thanks in advance.
No security...
It's easy to forget that a member reference in your class could be null. If you use what you think is an object reference but it's actually null, you get a NullPointerException.
There is no compiler-enforced way for a method to declare that it can only handle non-null parameters. The author can mark it with some annotation or put a note about it in the method documentation, but null values can still be passed and cause a NullPointerException or other exception of the author's choosing.
There is no compiler-enforced way for a method to declare it and return null. The author can mention it in the documentation or add some annotation to it, but if he doesn't notice or forgets, he can try to use a null return value as an object reference and cause a NullPointerException.
Code that once worked may stop working and start throwing NullPointerExceptions if a method that never returned a null value sometimes starts throwing a null value. Since the compiler doesn't enforce it, you get the exception at runtime instead of getting a compiler error so you can fix it.