💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
new 关键字表示一个类(第2.3节)或者一个抽象类型(第2.8节)被实例化。后面跟着将要被实例化的类型的类型路径(第3.7节)。它也可以列出显式的类型参数(第3.2节),在<>中,通过逗号分隔。 在一个括号() 中跟随构造器参数,同样使用逗号分隔。 > The new keyword signals that a class (2.3) or an abstract (2.8) is being instantiated. It is followed by the type path (3.7) of the type which is to be instantiated. It may also list explicit type parameters (3.2) enclosed in <> and separated by comma,. After an opening parenthesis () follow the constructor arguments, again separated by comma ,, with a closing parenthesis ) at the end. ~~~ class Main<T> { static public function main() { new Main<Int>(12, "foo"); } function new(t:T, s:String) { } } ~~~ main方法中我们实例化一个Main类自己的实例,有一个显式的类型参数 Int 和参数 12跟 "foo" 。就如我们看到的,语法非常类似函数的调用语法(第5.9节),通常称为构造函数调用。 > Within the main method we instantiate an instance of Main itself, with an explicit type parameter Int and the arguments 12 and "foo". As we can see, the syntax is very similar to the function call syntax (5.9) and it is common to speak of “constructor calls”.