<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Sorry, you can not do that.</div><div>Optional is a value based class [1] (see the javadoc) so the class has to be final.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>And more generally, the API of a classes of OpenJDK will not change based on some stylistic issue, OOP or not. <br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>regards,<br data-mce-bogus="1"></div><div>RĂ©mi Forax<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>[1] https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/doc-files/ValueBased.html<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Oleksii Kucheruk" <iselo+openjdk@raccoons.co><br><b>To: </b>"core-libs-dev" <core-libs-dev@openjdk.org><br><b>Sent: </b>Wednesday, August 23, 2023 4:43:17 PM<br><b>Subject: </b>RFE: Refactor java.util.Optional and add NonNull checks<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr">Hi there.<div>I have found that `java.util.Optional` is written procedural style and has `ifnonnull`  checks in each method. I propose to refactor `Optional` in accordance to OOP-style. This will eliminates all unnecessary `if`-statements, removes duplications and reduces bytecode size more then twice.</div><br><div>I have two solutions:</div><div>1. Completely dynamic that avoids single static `EMPTY` instance and unchecked casting of each `Optional.empty()`</div><div>2. Preserving original single static `EMPTY` per VM.</div><br><div>Also there are couple methods that throws NPE due to calling methods on null-objects and requires to add `Objects.requireNonNull(...)`.</div><br><div>OptionalInt, OptionalDouble, OptionalLong could be refactored same way even with remove of additional boolean variable `isPresent`.</div><br><div>Since I'm new here any guidance will be helpful.</div><div>Thank you in advance.</div></div><br></blockquote></div></div></body></html>