Dart Language Guide
  • Dart Language Guide (한국어)
  • LANGUAGE GUIDE
    • A basic Dart program
    • Important concepts
    • Keywords
    • Variables
    • Built-in types
      • Numbers
      • String
      • Booleans
      • Lists
      • Set
      • Maps
  • Functions
    • Parameters
    • The main() function
    • Functions as first-class objects
    • Anonymous functions
    • Lexical scope
    • Lexical closures
    • Testing functions for equality
    • Return values
    • Generators
Powered by GitBook
On this page
  1. Functions

Testing functions for equality

다음은 최상위 함수, 정적 메소드, 그리고 인스턴스 메소드의 동등성을 테스트하는 예시입니다

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

class A {
  static void bar() {} // A static method
  void baz() {} // An instance method
}

void main() {
  Function x;

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

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

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

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

  // These closures refer to different instances,
  // so they're unequal.
  assert(v.baz != w.baz);
}
PreviousLexical closuresNextReturn values

Last updated 2 years ago