dart學習(對象call方法)

1、如果類實現了call()方法,則該類的對象可以作爲方法使用

void main() {
  Person person = new Person();
  person.name = "Tom";
  person.age = 10;

  var result = person("Test", 20);
  print("result===>$result");
}

class Person {
  String name;
  int age;

  int call(String name, int age) {
    print("Name is $name,Age is $age");
    return 3;
  }
}

運行結果:

Name is Test,Age is 20
result===>3

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章