Special Methods
| String representation | Object copy | Value equality | Object comparison | Hash code | Object ID | ||
|---|---|---|---|---|---|---|---|
| Human-readable | Source-compatible | ||||||
| ABAP Objects | |||||||
| C++ (STL) | x == y | ||||||
| C# | x.ToString | x.Clone | x.Equals(y) | x.CompareTo(y) | x.GetHashCode | ||
| Java | x.toString | x.clone | x.equals(y) | x.compareTo(y) | x.hashCode | System.identityHashCode(x) | |
| JavaScript | x.toString | ||||||
| D | x.toString or std.conv.to!string(x) |
x.stringof | x == y | x.toHash | |||
| Objective-C (Cocoa) | |||||||
| Smalltalk | x displayString | x printString | x copy | x = y | x hash | x identityHash | |
| Python | str(x) | repr(x) | copy.copy(x) | x == y | cmp(x, y) | hash(x) | id(x) |
| Visual Basic .NET | x.ToString | x.Clone | x.Equals(y) | x.CompareTo(y) | x.GetHashCode | ||
| Eiffel | x.out | x.twin | x.is_equal(y) | When x is COMPARABLE, one can simply do x < y | When x is HASHABLE, one can simply do x.hash_code | When x is IDENTIFIED, one can simply do x.object_id | |
| PHP | sprintf("%s", x) | clone x | x == y | spl_object_hash(x) | |||
| Perl | "$x" | Data::Dumper->Dump(,) | Storable::dclone($x) | Scalar::Util::refaddr( $x ) | |||
| Perl 6 | ~x | x.perl | x.clone | x eqv y | x cmp y | x.WHICH | |
| Ruby | x.to_s | x.inspect | x.dup or x.clone |
x == y or x.eql?(y) |
x <=> y | x.hash | x.object_id |
| Windows PowerShell | x.ToString | x.Clone | x.Equals(y) | x.CompareTo(y) | x.GetHashCode | ||
| OCaml | Oo.copy x | x = y | Hashtbl.hash x | Oo.id x | |||
| F# | string x or x.ToString or sprintf "%O" x | sprintf "%A" x | x.Clone | x = y or x.Equals(y) | compare x y or x.CompareTo(y) | hash x or x.GetHashCode | |
Read more about this topic: Comparison Of Programming Languages (object-oriented Programming)
Famous quotes containing the words special and/or methods:
“Nature is a setting that fits equally well a comic or a mourning piece. In good health, the air is a cordial of incredible virtue. Crossing a bare common, in snow puddles, at twilight, under a clouded sky, without having in my thoughts any occurrence of special good fortune, I have enjoyed a perfect exhilaration. I am glad to the brink of fear.”
—Ralph Waldo Emerson (18031882)
“Parents ought, through their own behavior and the values by which they live, to provide direction for their children. But they need to rid themselves of the idea that there are surefire methods which, when well applied, will produce certain predictable results. Whatever we do with and for our children ought to flow from our understanding of and our feelings for the particular situation and the relation we wish to exist between us and our child.”
—Bruno Bettelheim (20th century)