Archived
This forum has been archived. Please start a new discussion on GitHub.
Why no .equals() for Java classes
The Java mapping for structs (section 10.7 of the manual) includes a .equals() method that compares member variables; however, the mapping for classes (section 10.14) doesn't create a .equals() method. Is there a reason for that?
NB: I'd like to be able to do comparisons between objects without having to write my own static comparison method, and I'd like to use classes rather than structs in Slice because of inheritance.
Thanks!
MEF
NB: I'd like to be able to do comparisons between objects without having to write my own static comparison method, and I'd like to use classes rather than structs in Slice because of inheritance.
Thanks!
MEF
0
Comments
-
Slice classes conceptually have reference semantics. For example, they can refer to other class instances, to themselves, or they can be null. If you compare two class references, you get "true" only if both references refer to the same class. Structs, on the other hand, are conceptually value types. In C++, this is much more obvious than in Java, because in C++ structs can be passed by value.0