以下の表記にてミューテータが定義できる。
def_=( )
実装例
package AbsoluteNumberDemo class AbsoluteNumber(num:Int) { private var _value = Math.abs(num) def value = _value // "getter" method def value_=(num:Int) = _value = Math.abs(num) // "setter" method } object Main extends Application { var absolute = new AbsoluteNumber(10) printf("Absolute = {0}\n", absolute.value) absolute.value = -5 printf("Absolute = {0}\n", absolute.value) }
実行結果
Absolute = 10 Absolute = 5