Skip to content

Commit

Permalink
mention identity comparison - fixes #30 (#69)
Browse files Browse the repository at this point in the history
* mention identity comparison - fixes #30

* fix identity for other types
  • Loading branch information
wilzbach authored and PetarKirov committed Feb 21, 2017
1 parent af4d9c2 commit 4065469
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions basics/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ it
that it isn't instantiated
- `super(..)` can be used to explicitly call the base constructor

### Checking for identity

For class objects, the `==` and `!=` operators compare the contents of the objects.
Therefore, comparing against `null` is invalid, as `null` has no contents.
The `is` compares for identity. To compare for nonidentity, use `e1 !is e2`.

```d
MyClass c;
if (c == null) // error
...
if (c is null) // ok
...
```

For `struct` objects all bits are compared,
for other operand types, identity is the same as equality.

### In-depth

- [Classes in _Programming in D_](http://ddili.org/ders/d.en/class.html)
Expand Down

0 comments on commit 4065469

Please sign in to comment.