<div dir="auto">You got how null and objects work slightly wrong resulting in some wrong assumptions.<div dir="auto"><br></div><div dir="auto">Remember all object variables in Java are just memory addresses (it's a bit more complicated but the details don't matter here). If you assign the object to the final field/ variable all you are doing is taking the memory address of the thing on the right and storing it in the field. The field itself also has an address so it would be possible to change it afterwards but saying the field is final makes that "illegal". </div><div dir="auto"><br></div><div dir="auto">The "change the variable itself afterwards" idea also is the reason you think the keyword should be at the use site.</div><div dir="auto"><br></div><div dir="auto">But this puts all the work and the track keeping to the runtime which now has to keep a list of what fields belong to this delayed object. Something the memory address (field) is already doing by itself in case of a valid object.</div><div dir="auto"><br></div><div dir="auto">So the simpler and more logical approach is to just set the field to the already prepared memory location the object will be initialized to. But mark that location so it will be treated as null if accessed through a field. This requires only 1 note for the runtime per object instead of per field. </div><div dir="auto"><br></div><div dir="auto">I don't know if you are familiar with C but here are the 2 approaches modeled in C:</div><div dir="auto"><br></div><div dir="auto">your approach:</div><div dir="auto"><br></div><div dir="auto">Foo* foo = null;</div><div dir="auto">Foo* foo2 = null;</div><div dir="auto"><br></div><div dir="auto">//runtime remembers fields</div><div dir="auto">Foo** __foo_field = &foo;</div><div dir="auto">Foo** __foo_field2 = &foo2;</div><div dir="auto"><br></div><div dir="auto">// some stuff</div><div dir="auto"><br></div><div dir="auto">//foo init</div><div dir="auto">Foo* actual_foo = malloc(sizeof(Foo));</div><div dir="auto">init_foo(actual_foo);</div><div dir="auto"><br></div><div dir="auto">// setting of every forwarded declare field</div><div dir="auto">*__foo_field = actual_foo;</div><div dir="auto">*__foo_field2 = actual_foo;</div><div dir="auto"><br></div><div dir="auto">// runtime forgetting now fully init fields. </div><div dir="auto">Foo** __foo_field = nullptr;</div><div dir="auto">Foo** __foo_field2 = nullptr;</div><div dir="auto"><br></div><div dir="auto">My approach:</div><div dir="auto"><br></div><div dir="auto">Foo* actual_foo = malloc(sizeof(Foo));</div><div dir="auto">Foo* foo = actual_foo;</div><div dir="auto">Foo* foo2 = actual_foo;</div><div dir="auto"><br></div><div dir="auto">//Runtime remembers memory as not initialized </div><div dir="auto">Foo* uninit_memory = actual_foo;</div><div dir="auto"><br></div><div dir="auto">//Some stuff</div><div dir="auto"><br></div><div dir="auto">//foo init</div><div dir="auto">init_foo(uninnit_memory);</div><div dir="auto"><br></div><div dir="auto">// runtime forgetting now initialized memory </div><div dir="auto">uninnit_memory = nullptr;</div><div dir="auto"><br></div><div dir="auto">As you can see your approach is taking linearly more recourses and is harder to manage as it scales with the number of effected fields while my approach is staying constant. </div><div dir="auto"><br></div><div dir="auto">Hope this cleared up some things.</div><div dir="auto">But don't underestimate the effort to implement it. It's likely to much effort in both approaches. </div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 7, 2023, 15:11 David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:monospace" class="gmail_default">I actually just remembered this.</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">I decided earlier on that any keyword that is used to denote this feature would be used where the variable is being passed in, like a "hall pass".</div><div><br></div><div><div style="font-family:monospace" class="gmail_default">Node a;</div><div style="font-family:monospace" class="gmail_default">Node b = new Node(__hall_pass a);</div><div style="font-family:monospace" class="gmail_default">     a = new Node(b);</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">I wanted to highlight this because your example put the keyword at the declaration site rather than the use site.</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">Doing it my way is clearer because, for example in the enum example I gave earlier, you change things to say this.</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">enum RPS7</div><div style="font-family:monospace" class="gmail_default">{</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">Rock(__hall_pass Scissors),</div><div style="font-family:monospace" class="gmail_default">Paper(Rock),</div><div style="font-family:monospace" class="gmail_default">Scissors(Paper),</div><div style="font-family:monospace" class="gmail_default">;</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">//etc</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">}</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">Plus, in my (very ignorant and uninformed) view of how the runtime works, putting the keyword at the use site would more closely map to what actions the runtime takes, as well as where it would do it.<br></div><br></div></div>
</blockquote></div>