Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
For example, in Ruby I can write
def initialize(price) @Current_price = price end
在 scala 中,您将所有初始化都写在类/特征/对象主体中:
class Foo(price: Int) { val currentPrice = price }
或者干脆
class Foo(val currentPrice: Int) { }
正如 DNA 所说,您可以将类体视为主要的构造方法。