Created
October 19, 2011 10:51
-
-
Save j5ik2o/1297960 to your computer and use it in GitHub Desktop.
Scala - クラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package money | |
import java.util.Currency | |
class Money(amnt : BigDecimal, creny : Currency){ | |
val amount = amnt // フィールド宣言 | |
val currency = creny // フィールド宣言 | |
// フィールド宣言でありながら、コンストラクタのボディとなっているので、処理も書けます。 | |
} | |
// 上記は下記のように省略して記述できる。 | |
class Money(val amount : BigDecimal, val currency : Currency) | |
val currency = Currency.getInstance("JPY") | |
val money = new Money(100, currency) | |
println(money.amount) | |
println(money.currency) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment