<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
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)">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>
</body>
</html>