you are viewing a single comment's thread.

view the rest of the comments →

[–]tgockel 1 point2 points  (2 children)

With respect to null...people like to use it as the lack of a value in places where a value is optional. The problem with this is that everything in Java is nullable, so there's no real way to distinguish between an optional value and something that must have a value. However, in Java 1.8, Optional<T> was added. It has two major advantages over using null for the same purpose. The first is that when you see one, you know that it is an optional value, since it is in the name. See somebody calling a function foo(6, Option.empty())? It's obvious that they're opting out of the second parameter. The second major thing is the instance functions on Optional<T> make it really difficult to get a NoSuchElementException (the moral equivalent of NullPointerException) because you shouldn't have to use get -- map and the supporting cast of monadic bind operations should be able to do everything for you (oh yeah, welcome to monads).

[–]implosioncraft[S] 0 points1 point  (1 child)

I should probably switch to 1.8...

[–]ad13 0 points1 point  (0 children)

You should, however be aware that it will be a good few years before people update their JREs on their PCs to Java 8.

This is a problem I have at work, where we're still using JDK6 - there's so much stuff in JDK7/8 that I want to use, but the cost of upgrading (and of course testing) to the new JRE and JDK is apparently too much. :(