Use the following problems to test your Optional programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:
- Initializing Optional: Write a program that exemplifies the right and wrong approaches for initializing Optional.
- Optional.get() and missing value: Write a program that exemplifies the right and wrong usage of Optional.get().
- Returning an already-constructed default value: Write a program that, when no value is present, sets (or returns) an already-constructed default value via the Optional.orElse() method.
- Returning a non-existent default value: Write a program that, when no value is present, sets (or returns) a non-existent default value via the Optional.orElseGet() method.
- Throwing NoSuchElementException: Write a program that, when no value is present, throws an exception of...