I get the intent of not having get() to prevent lazy unwraps, but sometimes I know for a fact a cap will always be there (for example, this is an internal cap for my mod that I attach myself).
Right now, I'm just doing orElseThrow(NullPointerException::new) which works but looks dirty.
Proposing to just add unwrap() or get() that does the line above
Or maybe throwing an IllegalStateException, as the OptionalCap was attempted to retrieve it's value whilst being in an illegal state?
(Guava uses IllegalState with their Optional's too...)
fwiw Java Optional uses NoSuchElementException
The lack of a get() method was an intentional design decision. Due to the removal of hasCapability, the OptionalCapabilityInstance is to be treated as a lazy value (think Schr枚dinger's capability instance), and only evaluated when absolutely needed, using the ifPresent and other available methods.
I hope some one create's a cat capability one day...
Most helpful comment
fwiw Java Optional uses NoSuchElementException