• NullPointerException
• Null checks everywhere
• NullPointerException
• Null checks everywhere
• Java 8 introduced a container class inspired by Haskell Maybe and Scala Option[T]
• Optional<Clazz> will hold an object of type Clazz, or it will just be an empty container if that object is null
• Optional.of()
• Optional.ofNullable()
• Optional.empty()
• Works seamlessly with any HTML input that is not required:
@RequestMapping(value = "/combined", method = RequestMethod.GET)
public String getCombinedThing(
@RequestParam(value = "thing1", required = true) String thing1,
@RequestParam(value = "thing2", required = false) Optional<String> thing2) {
final var response = thing1.concat(thing2.orElse(" but not thing 2"));
return response;
}