Testing functions for equality

Here’s an example of testing top-level functions, static methods, andinstance methods for equality:

1. void foo() {} // A top-level function

3. class A {
4. static void bar() {} // A static method
5. void baz() {} // An instance method
6. }

8. void main() {
9. var x;

11. // Comparing top-level functions.
12. x = foo;
13. assert(foo == x);

15. // Comparing static methods.
16. x = A.bar;
17. assert(A.bar == x);

19. // Comparing instance methods.
20. var v = A(); // Instance #1 of A
21. var w = A(); // Instance #2 of A
22. var y = w;
23. x = w.baz;

25. // These closures refer to the same instance (#2),
26. // so they're equal.
27. assert(y.baz == x);

29. // These closures refer to different instances,
30. // so they're unequal.
31. assert(v.baz != w.baz);
32. }