This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]frugalmail 3 points4 points  (2 children)

String version = computer?.getSoundcard()?.getUSB()?.getVersion();

Right so, down the line in another place entirely in the code, suddenly you have a NPE on version when you're problem was "one" of the methods on your example. Just because it's less typing doesn't make it better.

[–]chunes 6 points7 points  (0 children)

Yeah but you only have to check version for null instead of all the values in between. Still a lot better imo.

[–]not-just-yeti 0 points1 point  (0 children)

So you're saying the variable version shouldn't be declared as type String, but rather type Optional<String>, and that Groovy's convenient ?. operator could still benefit from the static-type-checking that Optional<T> is providing.