dart - Dart 中的 Python @property 等价物?

标签 dart

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

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

a = new Test()
print a.example

最佳答案

getters的概念看起来很相似:

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

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

关于dart - Dart 中的 Python @property 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427431/

相关文章:

flutter - 异步功能完成后如何返回数据

flutter - 如何在flutter中的下拉列表中显示Json数据

Dart 无法读取 readAsStringSync

dart - TextFormField Flutter 没有适当改变

class - Dart 确保类中的可选 bool 值不为空

algorithm - dart 的列表库使用什么排序算法?

dart - 在 polymer-1.0 中将样式属性绑定(bind)到组件属性

flutter - Flutter Delayed动画代码错误:在AnimationController.dispose()之后调用了AnimationController.forward()

if-statement - 如何在 Dart 的案例中访问 Switch 参数

flutter - 如何在共享首选项中将对象保存在json数组中?