Python @property在Dart中等效?

时间:2013-07-02 13:52:25

标签: dart

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

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

a = new Test()
print a.example

1 个答案:

答案 0 :(得分:4)

getters的概念看起来很相似:

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

main() {
  var a = new Test();
  print(a.example);
}