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.
たとえば、Rubyでは次のように書くことができます
def initialize(price) @Current_price = price end
Scalaでは、すべてのinitをクラス/トレイト/オブジェクト本体に記述します。
class Foo(price: Int) { val currentPrice = price }
または単に
class Foo(val currentPrice: Int) { }
DNAが言ったように、クラス本体は一次コンストラクターメソッドと考えることができます。