Give a Generic Maybe a Fallback Value
easyQuestion 496Maybe<T> wraps one value of any type that may be missing. A missing value is stored as null. The field and the constructor are written. Complete the two methods.
Requirements:
1. isPresent() returns true when a value is stored and false when the stored value is null.
2. orElse(T fallback) returns the stored value when one is present. Otherwise it returns fallback.
3. A stored 0 or an empty string still counts as present. Only null means missing.
Do NOT write a main method.
Expected output
true Jo false no nickname
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
GenericsClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.