<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
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 class="moz-cite-prefix">On 10/28/24 4:20 PM, Roger Riggs wrote:<br>
</div>
<blockquote type="cite" cite="mid:511f2bcd-f007-446b-8604-6b034c9c5ed4@oracle.com">
Hi,<br>
<br>
I think that's covered by the instance method
`Optional.orElse(def)`<br>
<br>
Regards, Roger<br>
<br>
[1]
<a class="moz-txt-link-freetext" href="https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Optional.html#orElse(T)" moz-do-not-send="true">https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Optional.html#orElse(T)</a><br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 10/28/24 3:40 PM, Emre Kaplan
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CADfcdzYOMLyXyk1Q-8Ek6G_baD7oBUCvByTsaDYjkSg89ywA7w@mail.gmail.com">
<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>
</body>
</html>