[External] : Re: Question about circular references

Ron Pressler ron.pressler at oracle.com
Tue Jul 4 16:06:31 UTC 2023



> On 4 Jul 2023, at 16:25, David Alayachew <davidalayachew at gmail.com> wrote:
> 
> But regardless, you are declaring this out of the blue. Where are you coming from when you say this? What backs this statement up? I have come to you with widely accepted definitions. If you are going to say that final fields, in this instance, don't permit cycles, I need you to explain how and why, not just claim that they do.

For the purpose of this discussion, final is a feature that requires a field to be assigned (only once) in the constructor. If it’s assigned a value arriving to the constructor from the outside, then that value cannot the object currently being constructed. (Yes, you can get around that by passing `this` from a constructor to other constructors). This is in contrast to non-final fields that can be assigned outside the constructor, and so can be assigned in methods that receive the current object itself as an argument, something that the constructor cannot do.

> By all means, I am not picky. Can you show me what this would look like though? I can understand how you would achieve immutability doing this, but not the directness constraint I am talking about above.

You create your nodes and then you set their references (say, from a builder class), but you don’t expose a public API that allows mutating your nodes.

— Ron



More information about the amber-dev mailing list