<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,</div><div dir="ltr"><br></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think that's covered by the instance method `Optional.orElse(def)`<br></blockquote><div> </div><div>Yes, but we should create an Optional object for calling orElse because it is not static. For just null-checking, java.util.Objects seems better too.</div><div> </div><div>And I checked discussions and saw this message:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><pre style="color:rgb(0,0,0)">I took Remi's point about the canonical coalescing operator not always returning non-null </pre></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><pre style="color:rgb(0,0,0)">but the push seems to be in the direction of making sure the result is always non-null.</pre></blockquote><div>Unless a coalescing operator is added, only requireNonNull methods are mostly wanted then.</div></div><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Roger Riggs <<a href="mailto:roger.riggs@oracle.com" target="_blank">roger.riggs@oracle.com</a>>, 28 Eki 2024 Pzt, 23:35 tarihinde şunu yazdı:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
Hi,<br>
<br>
I guess I'd stop slacking off and figure out where that method goes.<br>
It's not clear it belongs on Optional, since it doesn't produce or
consume an Optional.<br>
java.util.Objects is seems better as long as it can be named to
avoid any confusion with other methods.<br>
<br>
:) Roger<br>
<br>
<div>On 10/28/24 4:20 PM, Roger Riggs wrote:<br>
</div>
<blockquote type="cite">
Hi,<br>
<br>
I think that's covered by the instance method
`Optional.orElse(def)`<br>
<br>
Regards, Roger<br>
<br>
[1]
<a href="https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Optional.html#orElse(T)" target="_blank">https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Optional.html#orElse(T)</a><br>
<br>
<br>
<br>
<div>On 10/28/24 3:40 PM, Emre Kaplan
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hello,</div>
<div><br>
</div>
<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>
<div><br>
</div>
<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><br>
</div>
<div>Thanks in advance..</div>
</div>
</blockquote>
<br>
</blockquote>
<br>
</div>
</blockquote></div>
</div>
</div>