Hacker News new | ask | show | jobs
by gravypod 3470 days ago
Null is meant to be used when it is likely there is a default handling for the responce. For instance

   String favoriteColor = accounts.get(username);
   if (favoriteColor == null) favoriteColor = "blue";
   setWindowColorTo(favoriteColor);

Removing null does not make your code more safe. Wrapping Null in more code does not make your code more safe.

You get null for free. I could write the same think that optionals do in Java with 1 static method

    public static boolean isAbsent(Object o) { return o == null; }

    public static <T> T get(T o) {
        if (isAbsent(o)) throw new RuntimeException();
        return o;
    } 

Now you get your nice abstraction from an inlined function. Wrapping it in an object in my opinion is bloat around seomthing that doesn't need it.

The best chance your have to sell all Java devs on something is @Nullable which is a fantastic idea. It lets you know where null WILL propegate so you know where to control it. IT will also help you get out of "I see NullPointerException so therefor null is the problem, not my code!"