<div dir="ltr">Hi Emre,<div><br></div><div>Why wouldn't requireNonNullElse(o1, requireNonNull(o2)) or requireNonNull(requireNonNullElse(o1, o2)) suffice?</div><div><br></div><div>Regards,</div><div>Michael</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 28 Oct 2024 at 16:41, Emre Kaplan <<a href="mailto:emr3kp@gmail.com" target="_blank">emr3kp@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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></div>