jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: UnmodifiableJMeterVariables implementation
Date Sat, 29 Jul 2017 11:20:14 GMT
On 23 July 2017 at 15:45, Felix Schumacher
<felix.schumacher@internetallee.de> wrote:
> Hi all,
>
> I wonder if the implementation for 'equals', 'hashCode' and possibly
> 'toString' of UnmodifiableJMeterVariables are correct.
>
> I think - for symmetry and since they are not the same classes - the methods
> 'hashCode' and 'equals' should include a test for the class.
>
> Currently with:
>
>  JMeterVariables vars = somehowGetThem();
>  UnmodifiableJMeterVariables unmodifiable = new
> UnmodifiableJMeterVariables(vars);
>
> we have
>
>  unmodifiable.equals(vars) == true
>  vars.equals(unmodifiable) != true

That is clearly broken; equals() must be reflexive.

> and
>
>  unmodifiable.hashCode() == vars.hashCode()

That does not matter.

> I think we should have
>
>  unmodifiable.equals(vars) != true
>  vars.equals(unmodifiable) != true

OK

> and
>
>  unmodifiable.hashCode() != vars.hashCode()

Not necessary.

objects that are the same to equals() must have the same hashCode, but
the equal hashCodes don't have to compare as equal().

> What do you think?

See above.

Hashcode and equals() are tricky to do correctly, especially with subclasses.

>  Felix
>
>

Mime
View raw message