可以在dart中使用私有构造函数吗?

时间:2019-03-13 13:38:31

标签: dart

我能够在TypeScript中执行以下操作

class Foo {
  private constructor () {}
}

因此只能从类本身内部访问此constructor

如何在Dart中实现相同的功能?

2 个答案:

答案 0 :(得分:5)

只需创建一个以import React, { Component } from "react"; import ReactDOM from "react-dom"; import { Dropdown, Form } from "semantic-ui-react"; const trigger = ( <span style={{ marginTop: "2px" }}> <i aria-hidden="true" class="user big icon" size="big" /> </span> ); const options = [ { key: "user", text: "Account", icon: "user", value: "/accounts" }, { key: "settings", text: "Settings", icon: "settings", value: "/settings" }, { key: "sign-out", text: "Sign Out", icon: "sign out", value: "/sign-out" } ]; class App extends Component { move = (e, { value }) => { this.props.history.push('value') } render() { return ( <div> <Dropdown options={options} trigger={trigger} icon={null} onChange={this.move} /> </div> ); } } 开头的命名构造函数

_

然后只能从其类(和库)访问构造函数class Foo { Foo._() {} }

答案 1 :(得分:2)

没有任何代码的方法必须是这样的

class Foo {
  Foo._();
}