On Mon, 8 Jul 2024 09:55:27 GMT, Pavel Rappo <pra...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Object.java line 101:
>> 
>>> 99:      * implementation should not use excessive memory or time for its
>>> 100:      * computations and should return a result for cyclic data
>>> 101:      * structures.
>> 
>> Hello Joe, adding this text to set the expectations looks reasonable. 
>> However, I think the text "should return a result for cyclic data 
>> structures." feels a bit odd. If I understand correctly what it's trying to 
>> state is that for a class of the form:
>> 
>> 
>> class Foo {
>>    Bar bar;
>>    Foo self;
>>    
>>    public void setSelf() {
>>       this.self = this;
>>    }
>> }
>> 
>> then:
>> 
>> 
>> Foo foo = new Foo();
>> foo.toString(); // or foo.hashCode()
>> 
>> should be able to return the output from hashCode() and toString() even when 
>> an instance of `Foo` has a field which holds the same `Foo` instance. i.e. 
>> `toString()` and `hashCode()` should be able to handle re-entrancy and 
>> shouldn't consume excessive memory or time.
>> 
>> If that understanding is correct, then maybe we could improve that text to 
>> state it differently instead of cyclic data structures? I checked the JDK 
>> repo to see if this term has previously been used but it hasn't. Maybe we 
>> should just state that the hashCode() toString() methods should be able to 
>> deal with re-entrancy?
>
> My understanding is the same. Personally, the wording reads unambiguously. 
> The words "circular" and "circularity" can be seen throughout codebase, in 
> similar contexts.
> 
> FWIW, a simpler example can be constructed like this:
> 
>     var list = new ArrayList<>(); 
>     list.add(list);

Changed to "cyclic/circular".

The "A" in "DAG" stands for "acyclic", but circular may be more commonly used.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20063#discussion_r1668962044

Reply via email to