Closed GoogleCodeExporter closed 9 years ago
Patch:
https://github.com/igorgatis/protobuf-csharp-port/compare/issue72?expand=1
Original comment by igorga...@gmail.com
on 24 Mar 2014 at 2:58
I'm very nervous of overriding Equals on builders, due to their mutable nature.
I can see it being useful in tests, although you can always call Build instead
of course. But I really wouldn't want them to be used as keys in a dictionary
or anything like that.
Let me ponder on this one a bit. (I'll have a look at the Java code as well...)
Original comment by jonathan.skeet
on 24 Mar 2014 at 6:51
I've had a look at the Java code (I can't easily test it right now) and it
doesn't override equals/hashCode as far as I can tell. When would you want this
functionality (other than in tests, where it's not a problem to call Build)?
Original comment by jonathan.skeet
on 5 Apr 2014 at 3:14
In general, I always like to see a Builder as a "mutable" proto object. I'd
expect it to work exactly like a proto object except one can change it. It's
like "const SomeProto&" vs "SomeProto*" in C++ world.
I can think of a couple of scenarios where that would be useful but it feels
like careful design would suffice to workaround that.
Original comment by igorga...@gmail.com
on 7 Apr 2014 at 3:23
The problem is that mutable types are fundamentally *not* like immutable types
when it comes to equality.
In particular, the documentation for Object.Equals(Object) *specifically* says
it shouldn't be overridden in mutable types:
> You should not override Equals on a mutable reference type. This is because
overriding Equals requires that you also override the GetHashCode method, as
discussed in the previous section. This means that the hash code of an instance
of a mutable reference type can change during its lifetime, which can cause the
object to be lost in a hash table.
(As an example, StringBuilder doesn't override Equals(Object) - although
somewhat confusingly, it does add an overload of Equals(StringBuilder).)
Original comment by jonathan.skeet
on 7 Apr 2014 at 4:40
Perhaps we should close this one. I've used the API for a while now and I don't
really miss a Builder.Equal method.
Original comment by igorga...@gmail.com
on 24 Jul 2014 at 7:36
Sounds good to me :)
Original comment by jonathan.skeet
on 24 Jul 2014 at 7:43
Original issue reported on code.google.com by
igorga...@gmail.com
on 21 Feb 2014 at 11:02