<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<tt>For primitives, you can always force yourself to use Integer:<br>
<br>
   lazy Integer i = f();<br>
<br>
and make sure f() never returns null. You can do something
similar with a library class (e.g., Optional) for references. So
there are surely _safe_ ways to do it, albeit ugly ones. <br>
<br>
I kind of prefer to have boxing like this be explicit rather than
implicit; if the user thinks they're putting an `int` in their
class, I'd like to be as transparent about that as we can. <br>
<br>
You were willing to throw on null in the reference case; that can
also be simulated by:<br>
<br>
   lazy Foo f = requireNonNull(f());<br>
<br>
Which isn't even that ugly or expensive. So I suspect that this
is less of a problem that one might first think, but I could be
wrong.<br>
<br>
<br>
</tt><br>
<div class="moz-cite-prefix">On 4/18/2018 5:59 PM, Kevin Bourrillion
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGKkBkvjXh1MzJzaRRNWnj2L3d5a=7-rkr1vvqb3oQ8DNjJ+cw@mail.gmail.com">
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">For instance fields, we
have a choice; use extra space in the object to store the
"already initialized" bit, or satisfy ourselves with the trick
that String does with hashCode() -- allow redundant
recomputation in the case where the initializer serves up the
default value. <br>
</div>
</blockquote>
<div><br>
</div>
<div>I strongly suspect there isn't going to be any generally safe
way to do the latter.</div>
</blockquote>
<br>
</body>
</html>