<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></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>"Emre Kaplan" <emr3kp@gmail.com><br><b>To: </b>"jdk-dev" <jdk-dev@openjdk.org><br><b>Sent: </b>Monday, October 28, 2024 8:40:55 PM<br><b>Subject: </b>A static null-coalescing method<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"><div>Hello,</div></div></blockquote><div><br></div><div>Hello,<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><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"><br><div>I think <font face="monospace">java.util.Optional</font> class should have a static method named like </div><div><font face="monospace">getOrDefault(Object o, Object default)</font></div><div><font face="monospace"><br></font></div><div>In short, if an object is null, it should return the default object, otherwise the same object. And inside, default null check should be done. Same result can be achieved by method chaining of ofNullable and orElse, but then an object is created. I think it will be memory efficient because only one static method needs to be called. I don't know if it has been discussed before. </div><br><div>Also there is <span style="font-family:monospace">Objects.requireNonNullElse(Object o1, Object o2) </span></div><div>but the second parameter should be non-null.</div></div></blockquote><div><br data-mce-bogus="1"></div><div>It has been discussed multiple times,<br data-mce-bogus="1"></div><div>see <a href="https://bugs.openjdk.org/browse/JDK-8138963">https://bugs.openjdk.org/browse/JDK-8138963</a> and the linked discussions on core-libs-dev mailing list.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><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"><br><div>Thanks in advance..</div>
</div></blockquote><div><br></div><div>regards,<br data-mce-bogus="1"></div><div>RĂ©mi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>