3

Python 可以像使用装饰器的属性一样访问方法@property。Dart有这样的东西吗?

class Test():
    @property
    def example():
        return "This isn't really a property"

a = new Test()
print a.example
4

1 回答 1

4

getter的概念看起来很相似:

class Test {
  String get example {
    return "This isn't really a property";
  }
}

main() {
  var a = new Test();
  print(a.example);
}
于 2013-07-02T14:01:12.737 回答